W
W
Web Lizard2017-10-30 20:32:17
Twig
Web Lizard, 2017-10-30 20:32:17

How to write such a construction on TWIG?

There is such a design.

{% for product in order%}
{{ loop.index }}
{% endfor %}

But I need the loop.index variable to be output after the for and add one to it.
In php I would do it like this:
<?
$i = 0;
for (/*условие цикла*/) { 
  $i++;	
}
echo $i+1;
?>

But I don't know how to do it on TWIG. Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zorca, 2017-10-30
@zorca

In fact, such tasks should not be in front of the template. If you need to do this in Twig, look for troubles in your architecture. Twig is not an equivalent of PHP, its task is to output variables that are received in the controller to the template. In your case, you can simply get the number of elements in the array, either before or after the for:
{{ order|length }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question