title: How to assign local variable in Jquery template
body: <p>Below, I am trying to print replaced items using Jquery template. There I want to set a variable <strong>partHasBeenReplaced</strong> which later I can use to print the label and close the <code>&lt;span&gt;</code> element. </p>
  
  <ol>
  <li>How can I set variable there?</li>
  <li><p>How to find the last element of type "REPLACEMENT"? it may not be the last element of the array.</p>
  
  <pre><code>            {{each(i,ref) productReferences}}
                      {{if ref.referenceType == 'REPLACEMENT'}}
                          {{partHasBeenReplaced = 'true'}}
                      {{/if}}
              {{/each}}
  
              {{if partHasBeenReplaced == 'true'}}
                  &lt;span class="text-danger font-weight-bold pt-2"&gt;
                      This item has been replaced with:
              {{/if}}
  
              {{each(i,ref) productReferences}}
                      {{if ref.referenceType == 'REPLACEMENT'}}
                          {{= ref.target.code}} ,
                      {{/if}}
              {{/each}}
  
              {{if partHasBeenReplaced == 'true'}}
                  &lt;/span&gt;
              {{/if}}
  </code></pre></li>
  </ol>