title: Conditional Thymeleaf fragments
body: <p>I would like to create a list of up to three items using a template fragment. Three spaces for items will always be displayed regardless of whether or not there is an item, so it looks something like this.</p>
  
  <pre><code>&lt;div&gt;
    &lt;div th:if="${#lists.size(block.children) &gt; 0}"
      th:insert="code-block :: block(${block.children[0]})" 
      th:remove="tag"&gt;
    &lt;/div&gt;
  &lt;/div&gt;;
  &lt;div&gt;
    &lt;div th:if="${#lists.size(block.children) &gt; 1}"
      th:insert="code-block :: block(${block.children[1]})" 
      th:remove="tag"&gt;
    &lt;/div&gt;
  &lt;/div&gt;;
  &lt;div&gt;
    &lt;div th:if="${#lists.size(block.children) &gt; 2}"
      th:insert="code-block :: block(${block.children[2]})" 
      th:remove="tag"&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>However, even though the <code>th:if</code> statement evaluates as false with an empty list, it still attempts to execute the `th:include statement, giving me the following error:</p>
  
  <pre><code>Caused by: org.springframework.expression.spel.SpelEvaluationException:
  EL1025E:(pos 14): The collection has '0' elements, index '0' is invalid
  </code></pre>
  
  <p>How can I get the if statement to take precedence over the fragment execution?</p>