Reputation:
I'm looking for a way to get some id like :
first_1
/ first_2
/ etc etc
But currently i'm doing wrong
{% set nb = 0 %}
{% for resultat in resultats %}
{% if resultat.first == 1 %}
{% set nb=nb+1 %}
<tr id="first_"{{ nb }}>
This is giving id="first_"
and an other param "1"=""
Thanks for your help
Upvotes: 0
Views: 1823
Reputation: 3440
You can concat string in Twig with "~" (same as "." in php and "+" in javascript)
<tr id="{{ 'first_' ~ nb }}">
Upvotes: 0
Reputation: 14179
You have:
{{ "first_#{loop.index0}" }}
you don't need to manually create the incrementer.
Further info: How to concatenate strings in twig
Upvotes: 2