SimplGy
SimplGy

Reputation: 20437

liquid template `for` loop: how to `continue` to skip an iteration

I would like to skip an iteration based on a condition.

I'm using liquid templates as part of Jekyll.

I don't see a continue in the docs:

http://www.rubydoc.info/gems/liquid/Liquid/For

{% for page in site.pages %}
  {% if page.url == '/index.html' %}
    // Continue here
  {% endif %}
  {{ page.title }}
{% endfor %}

Upvotes: 7

Views: 5331

Answers (1)

SimplGy
SimplGy

Reputation: 20437

You can use the continue tag, which works just like a continue in any other language. It's documented in a separate section:

{% for page in site.pages %}
  {% if page.url == '/index.html' %}
    {% continue %}
  {% endif %}
  {{ page.title }}
{% endfor %}

Upvotes: 24

Related Questions