I need to create a filtered forloop within a forloop. The context is ecommerce. I have product categories, and, under each category, there are various products.
To list them out, here is what I do:
{% for c in categories %}
Products in {{ c.name }}:
{% for p in products %}
<table>
{% ifequal p.categoryname c.name %}
{% cycle '<tr>' '' '' %}
<td>{{ p.productname }}</td>
{% cycle '' '' '</tr>' %}
{% endifequal %}
</table>
{% endfor %}
{% endfor %}
I need to list the products in tables of rows of 3. However, cycling through products will not lead to the intended effect, because the cycle happens even if the ifequal statement is not fulfilled. Is there anyway to merge the products forloop and the ifequal condition, via filters, perhaps?
Thanks in advance!
Let {% regroup %} tag do the job.