Last active
April 29, 2016 09:29
-
-
Save mortendk/927eab28d6643daec03a to your computer and use it in GitHub Desktop.
twig loop template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# loop template #} | |
{% for item in items %} | |
{# assing foo, bar or baz to the var foo then print em out #} | |
{% | |
set var = [ | |
cycle(["foo", "bar", "baz"], loop.index), | |
] | |
%} | |
{% if loop.first %} | |
{# first #} {{ var }} | |
{% elseif loop.last %} | |
{# last #} {{ var }} | |
{% elseif loop.index == "2" %} | |
{# test on number #} {{ var }} | |
{% elseif loop.revindex = "2"%} | |
{# test on numbers left #} {{ var }} | |
{% else %} | |
{# default #} {{ var }} | |
{% endif %} | |
{% endfor %} | |
variables for loops: | |
{{ loop.index }} - count 1 - n | |
{{ loop.index0 }} - count 0 - n | |
{{ loop.revindex }} - revers count n - 1 | |
{{ loop.revindex0 }} - revers count n - 0 | |
{{ loop.length }} - how many loops | |
{{ cycle(["even", "odd"], loop.index) }} - cycle through vars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment