title: Thymeleaf use local variable for <tr> in table
body: <p>I use a normal html table for iterating through a list of objects in thymeleaf. </p>
  
  <p>I want to change the class of the <code>&lt;tr&gt;</code> tag changing by the value of the <code>providerResponse.status</code>. But this value is first known after the start of the iteration. So I think its not usable in the same <code>&lt;tr&gt;</code> row definition. </p>
  
  <p>I also used a local variable for switching the <code>&lt;td&gt;</code> class. But the local variable is just usable in the context of the used html attribute. So I needed to write the code several times.</p>
  
  <p><strong>Is it possible to use the local variable in the full context of the table?</strong></p>
  
  <p><strong>Is there a way to reduce the duplication of the same code?</strong> </p>
  
  <pre><code>&lt;tr th:each="providerResponse : ${providerResponses}"&gt;
  
    &lt;th:block th:switch="${providerResponse.status}"
      th:with="temp='active'"&gt;
      &lt;th:block th:case="'AVAILABLE'"&gt;
        &lt;th:block th:with="temp='success'"&gt;
          &lt;td th:class="${temp}" th:text="${providerResponse.executeDate}"&gt;&lt;/td&gt;
          &lt;td th:class="${temp}" th:text="${providerResponse.provider}"&gt;&lt;/td&gt;
          &lt;td th:class="${temp}" th:text="${providerResponse.status}"&gt;&lt;/td&gt;
        &lt;/th:block&gt;
      &lt;/th:block&gt;
      &lt;th:block th:case="'UNKNOWN'"&gt;
        &lt;th:block th:with="temp='danger'"&gt;
          &lt;td th:class="${temp}" th:text="${providerResponse.executeDate}"&gt;&lt;/td&gt;
          &lt;td th:class="${temp}" th:text="${providerResponse.provider}"&gt;&lt;/td&gt;
          &lt;td th:class="${temp}" th:text="${providerResponse.status}"&gt;&lt;/td&gt;
        &lt;/th:block&gt;
      &lt;/th:block&gt;
    &lt;/th:block&gt;
  &lt;/tr&gt;
  </code></pre>