I have tried to externalize the template folder of my spring webmvc proyect, I need this feature because the designer want to modify very often the html. And is to dificult for him to edit inside de a war file. I use thymeleaf as templateResolver
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="file:/opt/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="false" />
</bean>
I tried using this line, but it didn't work
<property name="prefix" value="file:/opt/templates/" />
How can I do that?
You can use FileTemplateResolver
instead of ServletContextTemplateResolver
.
Try this:
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.FileTemplateResolver">
<property name="prefix" value="/opt/templates/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="false" />
</bean>
The class version :
@Configuration
public class TemplateEngineConfig {
@Value("${templates.path}")
private String HTML_TEMPLATES_PATH;
@Bean
public TemplateEngine templateEngine() {
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
return templateEngine;
}
private TemplateResolver templateResolver() {
TemplateResolver resolver = new FileTemplateResolver();
resolver.setPrefix("/opt/templates/");
resolver.setSuffix(".html");
resolver.setCacheable(false);
return resolver;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With