title: Using variables to build fragment name in th:include - ThymeLeaf + Spring Boot
body: <p>I would like to use the <code>fragment</code> functionality without the <code>th:fragment</code> (just using id). And in my code, the target fragment to be included is dynamically built from an iterator. The problem is creating the proper expression for the <code>th:include</code> to be rendered correctly. I've tried Concatenation, Preprocessing and Literal Substitution as per the tutorial, but without result - makes me think - is this allowed in <code>th:include</code>?</p>
  
  <p>Fragment definition (It's in a file called <code>Comments.html</code> under my template, with my other templates).</p>
  
  <pre><code>&lt;div id="LOW_SCORE_COMMENT"&gt;
  </code></pre>
  
  <p>It's been called this way</p>
  
  <pre><code>&lt;div class="well" th:each="commentFragment : ${allComments}"&gt;
      &lt;div th:include="'Comments :: #' + {__${commentFragment}__}"&gt;
      &lt;/div&gt;          
  &lt;/div&gt;
  </code></pre>
  
  <p><code>allComments</code> is an <code>Iterator&lt;String&gt;</code>, and the Strings retrieved are the fragment id's, so it should then build out the entire page.
  But I get this error</p>
  
  <blockquote>
    <p><code>org.thymeleaf.exceptions.TemplateInputException: Error resolving template "'Comments", template might not exist or might not be accessible by any of the configured Template Resolvers</code></p>
  </blockquote>
  
  <p>Note the single quote between " and Comments in the error message.</p>
  
  <p>Do you have any suggestions?</p>
  
  <p>EDIT:
  i tried this code</p>
  
  <p><code>&lt;div class="well" th:each="commentFragment,iterstat : ${allComments}"&gt;
          &lt;div th:include="${commentFragment.getValue()}"&gt;&lt;/div&gt;</code></p>
  
  <p>essentially changed <code>allcomments</code> to a <code>TreeMap</code> to solve ordering issues, but now the error is as follows:</p>
  
  <blockquote>
    <p>org.thymeleaf.exceptions.TemplateInputException: Error resolving template
    "Comments :: #LOW_SCORE_COMMENT", template might not exist or might not be >accessible by any of the configured Template Resolvers </p>
  </blockquote>