a Sensio Labs Product

The flexible, fast, and secure
template engine for PHP

Functions » cycle

Table of Contents

Questions & Feedback

License

Creative Commons License Twig documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

cycle

The cycle function cycles on an array of values:

1
2
3
{% for i in 0..10 %}
    {{ cycle(['odd', 'even'], i) }}
{% endfor %}

The array can contain any number of values:

1
2
3
4
5
{% set fruits = ['apple', 'orange', 'citrus'] %}

{% for i in 0..10 %}
    {{ cycle(fruits, i) }}
{% endfor %}

Arguments

  • position: The cycle position
This website is powered by PHP and Twig. The Twig logo is © 2010-2012 Sensio Labs