swig for loop node.js, express, mongodb
Problem
I'm creating a for loop with swig engine. basically, if i have more than 4 tables under parent's td new tr will created and goes on... please help! :(
{% if style and style.length %}
{% for style in a %}
{% if loop.index0 % 4 === 0 && loop.index0 !== 0 %}
{% endif %}
{{style}}
{% endfor %}
{% endif %}
here's my JSON:
{style:"1" , a:"http://", img:"http://", price: 1, desc: "ahdf"},
{style:"2" , a:"http://", img:"http://", price: 11, desc: "adsdf"},
{style:"3" , a:"http://", img:"http://", price: 13, desc: "asdaf"},
{style:"4" , a:"http://", img:"http://", price: 1, desc: "asddf"},
{style:"5" , a:"http://", img:"http://", price: 51, desc: "asssdf"},
{style:"6" , a:"http://", img:"http://", price: 71, desc: "asdf"},
{style:"7" , a:"http://", img:"http://", price: 12, desc: "asddf"}
Problem courtesy of: wisleans
Solution
It looks like you are not closing the previous before creating a new one. Try this:
{% if loop.index0 % 4 === 0 && loop.index0 !== 0 %}
{% endif %}
Solution courtesy of: Matt Pennig
Discussion
View additional discussion.