title: Spring thymeleaf header and footer dynamic includes
body: <p>I recently started working with thymeleaf template engine in spring. What I want to achieve is - If my controller is this</p>
  
  <pre><code>@RequestMapping(value="/", method=RequestMethod.GET)
  public String index() {
      return "homePage";
  }
  </code></pre>
  
  <p>Then I want write HTML code in homePage.html without complete HTML definition like head, title, body etc.</p>
  
  <pre><code>&lt;div&gt;This is home page content&lt;/div&gt;
  </code></pre>
  
  <p>Dont want to write in homePage.html like this. </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" &gt;
  &lt;head&gt;
      &lt;title&gt;Spring MVC Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div th:include="fragments/header::head"&gt;&lt;/div&gt;
      &lt;div&gt;This is home page content&lt;/div&gt;
      &lt;div th:include="fragments/footer::foot"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>I prefer to take head part for header fragment, content from controller and footer from footer fragment.</p>
  
  <p>So in total - How I can achieve this:</p>
  
  <p><strong>/fragment/header.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" &gt;
  &lt;head&gt;
      &lt;title&gt;Spring MVC Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  </code></pre>
  
  <p><strong>/home.html</strong></p>
  
  <pre><code>&lt;div&gt;This is home page content&lt;/div&gt;
  </code></pre>
  
  <p>(this throw error)</p>
  
  <p><strong>/fragment/footer.html</strong></p>
  
  <pre><code>  &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>Note: I already seen these examples</p>
  
  <ul>
  <li><a href="http://www.thymeleaf.org/doc/articles/layouts.html" rel="noreferrer">http://www.thymeleaf.org/doc/articles/layouts.html</a></li>
  <li><a href="https://looksok.wordpress.com/2014/06/28/spring-website-layouts-ssi-with-thymeleaf-templates/" rel="noreferrer">https://looksok.wordpress.com/2014/06/28/spring-website-layouts-ssi-with-thymeleaf-templates/</a></li>
  <li><a href="http://blog.codeleak.pl/2013/11/thymeleaf-template-layouts-in-spring.html" rel="noreferrer">http://blog.codeleak.pl/2013/11/thymeleaf-template-layouts-in-spring.html</a></li>
  </ul>