select previous item in twig for loop -


i use twig , have data in array. use loop access data this:

{% item in data %}     value : {{ item }} {% endfor %} 

is possible access previous item in loop? example: when i'm on n item, want have access n-1 item.

there's no built-in way that, here's workaround:

{% set previous = false %} {% item in data %}     value : {{ item }}      {% if previous %}         {# use #}     {% endif %}      {% set previous = item %} {% endfor %} 

the if neccessary first iteration.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -