html - How to add class if single tag? -


i have 4 <li></li>, showed or not.

{% if li == 1 %}{% endif %} 

how add class if 1 (single) <li></li> showed?

if display collection of items can check length of array. example:

{% set elems = ['1','2'] %} {# {% set elems = ['1'] %} #}  {%for elem in elems %}   <li{% if elems|length == 1 %} class="single" {% endif %}>     {{elem}}   </li> {%endfor%} 

here working example

hope help


Comments