0

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

1

3 Answers 3

2

You have:

  1. loop variables
  2. String Interpolation
{{ "first_#{loop.index0}" }} 

you don't need to manually create the incrementer.

Further info: How to concatenate strings in twig

Sign up to request clarification or add additional context in comments.

Comments

1

You can concat string:

{% set nb = 0 %} <tr id="first_{{ nb }}"> 

Comments

0

You can concat string in Twig with "~" (same as "." in php and "+" in javascript)

 <tr id="{{ 'first_' ~ nb }}"> 

Comments