lundi 16 mars 2015

Working with Thymeleaf Page Layouts


Vote count:

0




I am trying use thymeleaf page layouts in my current spring-boot project. I add this to my index.html view (place in resources/templates/public):



<nav class="navbar navbar-default navbar-fixed-top">
<div th:include="menu :: menu">...</div>
</nav>


the view menu.html is this:



<!DOCTYPE html>
<html>
<head></head>
<body>

<div class="container" th:fragment="menu">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" th:href="@{/}">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">

</ul>
<ul class="nav navbar-nav navbar-right">
<li sec:authorize="isAnonymous()"><a th:href="@{/signin}">Entrar</a></li>
<li sec:authorize="isAnonymous()"><a th:href="@{/signup}">Cadastro</a></li>
<li sec:authorize="isAuthenticated()"><a th:href="@{/logout}">Logout</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>

</body>
</html>


but when I run the project, I am getting this error:



Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "menu", template might not exist or might not be accessible by any of the configured Template Resolvers (public/index:77)] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "menu", template might not exist or might not be accessible by any of the configured Template Resolvers (public/index:77)


I have this configuration for thymeleaf in my application.properties file:



# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false


and I have this configuration class too:



@Configuration
public class ThymeleafContext {

@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();

engine.addTemplateResolver(templateResolver());

final Set<IDialect> dialects = new HashSet<IDialect>();
dialects.add( new SpringSecurityDialect() );
engine.setDialects( dialects );

return engine;
}

public ITemplateResolver templateResolver() {
TemplateResolver resolver = new TemplateResolver();
return resolver;
}

}


what I am missing here?



asked 22 secs ago







Working with Thymeleaf Page Layouts

Aucun commentaire:

Enregistrer un commentaire