May 22, 2020
Estimated Post Reading Time ~

How to total up first few elements in a for each loop of Sightly?

How to add the first three elements of a for loop in sightly and show the value as Total. I have code as below

{{each(i, provision) provisionTypes}}
    <label class="day-provision-label">
        <input type="checkbox" class="day-provision" data-provision-type="${provision}" {{if day[provision]}}checked{{/if}} {{if !day.working}}disabled{{/if}}>
        ${provision.charAt(0).toUpperCase() + provision.slice(1)}
        <span class="provision-rate ui-supporting-text">
            $${rates[provision].toFixed(5)}
        </span>
    </label>
{{/each}}
What I want to do is that in the each for loop, I want to display to the total of the first three elements... Not sure how to?

Best How To:
I don't think that is possible in Sightly. It is meant to be only for presentation purposes. it even lacks arithmetic operations, so you cannot really add numbers with it. You'll have to do it in the backend. You can use the WCMUse API (in it's java or javascript forms) to add some logic to your component


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.