I
I
ILoveYAnny2016-07-14 13:54:27
Twig
ILoveYAnny, 2016-07-14 13:54:27

How to make a simple loop in Twig while i < n?

Hello, I ran into a very simple problem, but for some reason I can not find the answer in the documentation.
I have a line counter, I need to repeat the iterations of the loop until the desired number is printed.
In the documentation, the following example\

{% for i in 0..10 %}
    * {{ i }}
{% endfor %}

But by substituting the counter for the numbers, Twig doesn't print anything. And passing an array with numbers is wrong. Please tell me the analogue for i

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2016-07-14
@ILoveYAnny

{#
    n разумеется можно задавать и в логике (или в gulp-data, если это сборщик фронта),
    это просто переменная
#}
{% set n = 3 %}
{% for i in range(1, n) %}
    {{ i }},
{% endfor %}

V
Vincent1, 2016-07-14
@Vincent1

{% for i in n %} 
  Текущий: {{ loop.index }}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question