-
How to set increment variable in twig?
almost 9 years ago
-
over 6 years ago
Superb explanation and nicely presented! Even the new toggle is interesting and most awaited function. -
almost 9 years ago
Hello Friends
This PHP tutorial will help you to implement a set of incremental variable in twig which you can use to show listing in twig with numbers in the first column. This will include defining twig variable and increment/decrements variable value in twig. lets see how, with the help of below code:
{% set inc = 1 %}
{% for value in communities %}
<tbody>
<tr>
<td>{{inc}}</td> <!-- HERE WE ARE SHOWING INCREMENTED NUMBER -->
<td>{{value.community_description}}</td>
<td><img src="{{value.community_photo_one}}" height="75" width="100"></td>
<td>{{value.created_on}}</td>
<td><a href="/admin/update_community?id={{value.id}}"><button class="btn btn-round btn-primary" type="button">Update</button></td>
</tr>
</tbody>
{% set inc = inc + 1 %}
{% endfor %}
{% set inc = 1 %}
{% for value in communities %}
<tbody>
<tr>
<td>{{inc}}</td> <!-- HERE WE ARE SHOWING INCREMENTED NUMBER -->
<td>{{value.community_description}}</td>
<td><img src="{{value.community_photo_one}}" height="75" width="100"></td>
<td>{{value.created_on}}</td>
<td><a href="/admin/update_community?id={{value.id}}"><button class="btn btn-round btn-primary" type="button">Update</button></td>
</tr>
</tbody>
{% set inc = inc + 1 %}
{% endfor %}
over 6 years ago
1 Comment(s)