Loop through array in Twig I have this array

{% set icons = { 1: 'glyphicon glyphicon-asterisk', 
                 2: 'glyphicon glyphicon-plus', 
                 3: 'glyphicon glyphicon-minus',
                 4: 'glyphicon glyphicon-euro'   
                 } 
%}


I want to loop through it and print like this

&lt;li{{ item.attributes.addClass('pos' ~ loop.index, icons[loop.index]) }}&gt;
Simple:

Twig:


&lt;ul&gt;
  {% for key, icon in icons %}
    &lt;li{{ item.attributes.addClass('pos' ~ key, icon) }}&gt;
  {% endfor %}
&lt;/ul&gt;


Source:
http://twig.sensiolabs.org/doc/tags/for.html