martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
415 stars 22 forks source link

Add `{{ loop.odd? }}` and `{{ loop.even? }}` properties to the for loop variable #201

Closed ellmetha closed 4 months ago

ellmetha commented 7 months ago

Description

In order to make it easier to implement specific templates with for loops, let's ensure that the loop contextual variable also provides odd? and even? attributes.

For example:

{% for x in items %}
  {% if loop.even? %}
    Do something...
  {% else %}
    Do something else...
  {% endif %{
{% endfor %}