Iterators

PieCrust returns iterator objects as template data in several cases: pagination.posts, assets, site.pages, etc. Any time there’s a list of stuff, you can bet it’s returned as an iterator object.

At first glance, there’s not much difference with a simple list:

{% for page in site.pages %}
* [{{page.title}}]({{page.url}})
{% endfor %}

But the iterator includes features that, although they can be emulated with enough templating code, are much faster to achieve with the shortcut functions available here.

For example, if you want to get the first 10 pages that have the tag pastry, you can do this:

{% for page in site.pages.has_tags('pastry').limit(10) %}
* [{{page.title}}]({{page.url}})
{% endfor %}

You can even achieve more elaborate filtering with the filter syntax, too.