Loops

For loop

This will split a list of comma separated Custom Fields and loop through them.

<ul>{% for key in "[post_custom_fields]"|split(',') %}
  <li>{{ key|trim }}</li>
{% endfor %}</ul>

You can also use Post Status Notifier’s placeholders ending with “_array” (which are PHP arrays internally) to loop through them directly.

<ul>{% for key in [post_custom_fields_array] %}
  <li>{{ key|trim }}</li>
{% endfor %}</ul>

Three column design

This is an example of how to split an array into three parts and show the values in three columns. It uses PSN’s custom filter divide.

<div>
    {% for part in [post_categories_array]|divide(3) %}
        <div style="float: left; width: 33%;">
            <ul>
                {% for column in part %}
                <li>{{ column }}</li>
                {% endfor %}
            </ul>
        </div>
    {% endfor %}
    <div style="clear: both;"></div>
</div>

Note

Check out the Twig documentation page for more details about the for loop.