Fahmi Rizky Nugraha
Fahmi Rizky Nugraha

Reputation: 19

How sum Twig Template

i have code {% for defect in data %}

            <td>{{ defect.name }}</td>
             {% for times in time %}
             <td>{{ attribute(defect, times) }}</td>
            {% endfor %}
        </tr>
          {% endfor %}
          <tr>
              <td>Total</td>
               {% for times in time %}
               <td>in here</td>
            {% endfor %}
          </tr>

i want to sum {{ attribute(defect, times) }}

Upvotes: 0

Views: 1631

Answers (1)

Alvin Bunk
Alvin Bunk

Reputation: 7764

You appear to have too many {% endfor %} tags.

But what you can do is something like this:

{% set total = 0 %}
...
   {% for times in time %}
   {% set total = total + attribute(defect, times) %}
...

<td>Total equals: {{ total }}</td>

Essentially creating a variable called total and then in your loop add the attribute value. Hopefully you get the idea.

Upvotes: 2

Related Questions