“Valor clave de twig foreach” Código de respuesta

Valor clave de twig foreach

{% for key, user in users %}
    <li>{{ key }}: {{ user.username }}</li>
{% endfor %}
Easy Elk

bucle de ramas

loop.index	    The current iteration of the loop. (1 indexed)
loop.index0	    The current iteration of the loop. (0 indexed)
loop.revindex	The number of iterations from the end of the loop (1 indexed)
loop.revindex0	The number of iterations from the end of the loop (0 indexed)
loop.first	    True if first iteration
loop.last	    True if last iteration
loop.length	    The number of items in the sequence
loop.parent	    The parent context

{% for user in users %}
    {{ loop.index }} - {{ user.username }}
{% endfor %}
Annoying Ant

Twig para la tecla de bucle

{% for key, user in users %}
	<li>{{ key }}: {{ user.username|e }}</li>
{% endfor %}
Frail Finch

Respuestas similares a “Valor clave de twig foreach”

Preguntas similares a “Valor clave de twig foreach”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código