thymeleaf / thymeleaf-docs

Thymeleaf documentation
Apache License 2.0
44 stars 54 forks source link

Possible Bug(fix) of extending Thymleaf sayhelloextendingthymeleaf5minutes.md #98

Open robiasto opened 4 months ago

robiasto commented 4 months ago

Actual example found here does not work for me.

@Bean
public SpringTemplateEngine templateEngine(){
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setEnableSpringELCompiler(true);
    templateEngine.setTemplateResolver(templateResolver());
    templateEngine.addDialect(new HelloDialect());

    return templateEngine;
}

Problems:

  1. templateResolver() not implemented.
  2. Other dialects like for exanple "thymeleaf-layout-dialect" don't work any more.

My Fix

@Bean
    public SpringTemplateEngine templateEngine(ClassLoaderTemplateResolver templateResolver,  ObjectProvider<IDialect> dialects){
        SpringTemplateEngine templateEngine  = new SpringTemplateEngine();
        templateEngine.setEnableSpringELCompiler(true);
        templateEngine.setTemplateResolver(templateResolver);
        dialects.orderedStream().forEach(templateEngine::addDialect);
        templateEngine.addDialect(new HelloDialect());

        return templateEngine;
    }