Below, I am trying to print replaced items using Jquery template. There I want to set a variable partHasBeenReplaced which later I can use to print the label and close the <span> element.
- How can I set variable there?
How to find the last element of type "REPLACEMENT"? it may not be the last element of the array.
{{each(i,ref) productReferences}} {{if ref.referenceType == 'REPLACEMENT'}} {{partHasBeenReplaced = 'true'}} {{/if}} {{/each}} {{if partHasBeenReplaced == 'true'}} <span class="text-danger font-weight-bold pt-2"> This item has been replaced with: {{/if}} {{each(i,ref) productReferences}} {{if ref.referenceType == 'REPLACEMENT'}} {{= ref.target.code}} , {{/if}} {{/each}} {{if partHasBeenReplaced == 'true'}} </span> {{/if}}
In order to assign data to an element using such templates, it better to use attributes. We can access create/update/remove attribute using JavaScript.
For an example, if you want to add a data for
<span>then you can do it using -It can be accessed in JavaScript using below method -