symfony - How to make 3 columns table with Twig in Symfony2 -


i new twig , symfony2. wondering how can create 3 column table twig. data comes database

so far i've tried still nothin works. found on stackoverflow making 2 column table, , worked except me. want 3 columns .

<table>   {% var in var1 %}     {% if (loop.index % 2) %}<tr>{% endif %}     <td>       <div class="bloc">         <a href="{{ path('xxxxxxx', {'id':var.id}) }}">         <span>{{ var.name}}  </spann></a></div>         <img src="{{ asset(var.image ) }}"  />           </div>     </td>     {% if (loop.index % 2) , loop.last %}       <td>&nbsp</td>     {% endif %}     {% if (loop.index0 % 2) or loop.last %}</tr>{% endif %}   {% endfor %} </table>   ex: var1  contains names , pictures database. name1  name2  name3 name4  name5  name6 ... 

this have atm

name1   name2 name3   name4   name5 name6   name7   name8 

my solution works number of columns:

{% set columns = 3 %} {% name in names %}     {% if loop.first or loop.index0 divisibleby(columns) %}         <tr>     {% endif %}      <td>{{ name }}</td>      {% if loop.last , loop.index not divisibleby(columns) %}         {% n in range(low=columns - (loop.index % columns), high=1, step=-1) %}             <td>&nbsp;</td>         {% endfor %}     {% endif %}     {% if loop.last or loop.index divisibleby(columns) %}         </tr>     {% endif %} {% endfor %} 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -