Hello. Do you mean something like this?
{{#each_sum items id="item-table" sum-on="price" sum-placeholder="csum"}}
<span>{{name}} | Price: {{price}}, Cumulative: {{csum}}</span>
{{/each_sum}}
<div>Total: {{sum items sum-on="price"}}</div>
With example input of the form:
{
items: [
{
name: "ItemA",
price: 5.99
},
{
name: "ItemB",
price: 4.99
},
],
}
It would output:
<div>
<ul sum-placeholder="csum" sum-on="price" id="item-table">
<li><span>ItemA | Price: 5.99, Cumulative: 5.99</span></li>
<li><span>ItemB | Price: 4.99, Cumulative: 10.98</span></li>
</ul>
</div>
<div>Total: 10.98</div>
If so, let me know - I'm new to the platform, so I would like to help you out with this to gain some reputation.
I've already tried the example I've sent, so if that functionality is satisfactory, I can send you the code very soon.
The way I went about it:
#each_sum helper:
- I defined a custom block helper that iterates over the list and maintains a running total
- the sum-on="price" hash argument lets you define on which property to sum
- the sum-placeholder="csum" hash argument is optional, defaults to csum, and it lets you specify where in the template below should the cummulative sum appear.
sum helper:
- just a regular custom helper that uses the sum-on="price" hash argument to determine on which property to sum