Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set increment variable in twig?

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 5.71k
    Comment on it

    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:

    1. {% set inc = 1 %}
    2. {% for value in communities %}
    3. <tbody>
    4. <tr>
    5. <td>{{inc}}</td> <!-- HERE WE ARE SHOWING INCREMENTED NUMBER -->
    6. <td>{{value.community_description}}</td>
    7. <td><img src="{{value.community_photo_one}}" height="75" width="100"></td>
    8. <td>{{value.created_on}}</td>
    9. <td><a href="/admin/update_community?id={{value.id}}"><button class="btn btn-round btn-primary" type="button">Update</button></td>
    10. </tr>
    11. </tbody>
    12. {% set inc = inc + 1 %}
    13. {% endfor %}

     

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: