CMS Development

Anonymous
Not applicable

Calculate sum total of Loop

SOLVE

Need the subtotal of all rows in a loop.  I can't seem to find a way to complete this expression to add up all the line item amounts into a single subtotal.   

 

{% set amount = '{{ item.item_quantity * item.item_price }}' %}


{% for item in module.line_item %}
<tr style="height: 48px;">
<td class="hidden">{{ item.stripe_price_api_id }}</td>
<td >{{ item.line_item_description }}</td>
<td style="text-align: right;">{{ item.item_quantity }}</td>

 

<td style="text-align: right">${{ item.item_price }}</td>
<td style="text-align: right">${{ amount }}</td>
</tr>
{% endfor %}Screen Shot 2020-12-24 at 1.20.23 AM.png

0 Upvotes
1 Accepted solution
Solution
Anonymous
Not applicable

Calculate sum total of Loop

SOLVE

Answered: 
{% for item in module.line_item %}
{% set amount = item.item_quantity * item.item_price %}
{% set total = total + amount %}

<tr style="height: 48px;">
<td class="hidden">{{ item.stripe_price_api_id }}</td>
<td >{{ item.line_item_description }}</td>
<td style="text-align: right;">{{ item.item_quantity }}</td>
<td style="text-align: right">${{ item.item_price }}</td>
<td style="text-align: right">${{ item.item_quantity * item.item_price }}</td>
</tr>

{% endfor %}
<!-- Line Item Subtotal -->
<tr style="height: 24px;">
<td><strong>{{ module.total_label }}</strong></td>
<td></td>
<td style="text-align: right;">Subtotal</td>
<td style="text-align: right;"><strong>
{% for item in module.line_item %}
{% set amount = item.item_quantity * item.item_price %}
{% set total = total + amount %}
{% if loop.last %}
${{ total }}
{% endif %}

{% endfor %}

</strong></td>
</tr>

View solution in original post

1 Reply 1
Solution
Anonymous
Not applicable

Calculate sum total of Loop

SOLVE

Answered: 
{% for item in module.line_item %}
{% set amount = item.item_quantity * item.item_price %}
{% set total = total + amount %}

<tr style="height: 48px;">
<td class="hidden">{{ item.stripe_price_api_id }}</td>
<td >{{ item.line_item_description }}</td>
<td style="text-align: right;">{{ item.item_quantity }}</td>
<td style="text-align: right">${{ item.item_price }}</td>
<td style="text-align: right">${{ item.item_quantity * item.item_price }}</td>
</tr>

{% endfor %}
<!-- Line Item Subtotal -->
<tr style="height: 24px;">
<td><strong>{{ module.total_label }}</strong></td>
<td></td>
<td style="text-align: right;">Subtotal</td>
<td style="text-align: right;"><strong>
{% for item in module.line_item %}
{% set amount = item.item_quantity * item.item_price %}
{% set total = total + amount %}
{% if loop.last %}
${{ total }}
{% endif %}

{% endfor %}

</strong></td>
</tr>