...

Text file src/github.com/noirbizarre/gonja/testData/statements/for.tpl

Documentation: github.com/noirbizarre/gonja/testData/statements

     1{% for comment in complex.comments %}[{{ loop.index }} {{ loop.index0 }} {{ loop.first }} {{ loop.last }} {{ loop.revindex }} {{ loop.revindex0 }}] {{ comment.Author.Name }}
     2
     3{# nested loop #}
     4{% set parent = loop %}
     5{% for char in comment.Text %}{{ parent.index0 }}.{{ loop.index0 }}:{{ char|safe }} {% endfor %}
     6
     7{% endfor %}
     8
     9reversed
    10'{% for item in simple.multiple_item_list|reverse %}{{ item }} {% endfor %}'
    11
    12sorted string map
    13'{% for key in simple.strmap|sort %}{{ key }} {% endfor %}'
    14
    15sorted int map
    16'{% for key in simple.intmap|sort %}{{ key }} {% endfor %}'
    17
    18sorted int list
    19'{% for key in simple.unsorted_int_list|sort %}{{ key }} {% endfor %}'
    20
    21reversed sorted int list
    22'{% for key in simple.unsorted_int_list|sort|reverse %}{{ key }} {% endfor %}'
    23
    24reversed sorted string map
    25'{% for key in simple.strmap|sort|reverse %}{{ key }} {% endfor %}'
    26
    27reversed sorted int map
    28'{% for key in simple.intmap|sort|reverse %}{{ key }} {% endfor %}'
    29
    30key, value sorted string map
    31{%- for key, value in simple.strmap|dictsort %}
    32{{ key }}: {{ value }}
    33{%- endfor %}
    34
    35(key, value) 2-list key
    36{%- for key, value in [['key', 'value'], ['2nd key', '2nd value']] %}
    37{{ key }}: {{ value }}
    38{%- endfor %}
    39
    40(key, value) 2-tuple key
    41{%- for key, value in (('key', 'value'), ('2nd key', '2nd value')) %}
    42{{ key }}: {{ value }}
    43{%- endfor %}
    44
    45If expression
    46{%- for person in persons if person.Gender is equalto "male" %}
    47{{ person.FirstName }} {{ person.LastName }}
    48{%- endfor %}
    49
    50If expression and loop
    51{%- for person in persons if person.Gender is equalto "male" %}
    52{{ person.FirstName }} {{ person.LastName }} {{ loop.index }} {{ loop.revindex }} {{ loop.first }} {{ loop.last }}
    53{%- endfor %}
    54
    55Cycle
    56{%- for idx in range(4) %}
    57{{ idx }} {{ loop.Cycle('even', 'odd') }}
    58{%- endfor %}
    59
    60Else
    61{%- for idx in [] %}
    62Should not go there
    63{%- else %}
    64Nothing
    65{%- endfor %}
    66
    67Changed
    68{%- for idx in [1, 2, 2, 3]  %}
    69{{ idx }}: {{ loop.Changed(idx) }}
    70{%- endfor %}
    71
    72Prev/Next items
    73{%- for idx in range(3)  %}
    74{{ idx }}: prev: {{ loop.PrevItem }} next: {{ loop.NextItem }}
    75{%- endfor %}
    76
    77Prev/Next items 2-tuple
    78{%- for k, v in [(1, 'first'), (2, 'second'), (3, 'third')]  %}
    79{{ k }} {{ v }}: prev: {{ loop.PrevItem }} next: {{ loop.NextItem }}
    80{%- endfor %}
    81
    82Prev/Next items with if
    83{%- for idx in range(6) if idx is even  %}
    84{{ idx }}: prev: {{ loop.PrevItem }} next: {{ loop.NextItem }}
    85{%- endfor %}

View as plain text