1

I'm using Charge to collect donations toward individual projects for a charity.

On the frontend, I want to display how much has been raised for an individual project.

To get a list of charges for a project, I'm doing

{% set charges = craft.charge.charges({  
      search : { query : 'projectDonateTo:' ~ entry.id }}
   )%}

{% for charge in charges %}
    {{ charge.amount }}
{% endfor %}

which obviously loops through all charges but I can't fathom how to total these together.

Any ideas?

1

Can you not do:

{% set total = 0 %}

{% for charge in charges %}
    {% set total = total + charge.amount %}
{% endfor %}

{{ total|number_format(2, '.', ',') }}

?

| improve this answer | |
  • OK - it did but need to {% set total = total + charge.amount %} for it to work. If you want to edit the answer, I'll mark it off. – Steven Grant May 11 '17 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.