How Would You Make A Two Column Table With Twig?

前端 未结 3 1306
渐次进展
渐次进展 2021-02-05 07:30

I can\'t for the life of me figure out how to add a every OTHER iteration in a Twig loop.

For instance:

$numArray = a         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 08:16

    Something like this would work:

    
      {% for num in numArray %}
          
      {% if loop.index is even %}
        
      {% endif %}
      {% endfor %}
    
      {% if num|length is odd %}
        
      {% endif %} 
      
    {{num}}

    An alternative way, that feels much less hacky:

    
      {% for i in range(0, numArray|length-1, 2) %}
      
      {% endfor %}
    
    {{ numArray[i] }} {{ numArray[i+1]|default("") }}

提交回复
热议问题