Objects

Collection

Last updated: · Published:

A collection of records for a certain Content Type. This object is returned when a content type for posts' plural name is called on site, e.g. site.pages. A collection is also returned when a content type's plural name is called on the site.content_objects container object for generic content.

collection

When no attribute is called on the collection, it outputs all records inside as an array. E.g. calling site.pages just outputs all posts with the post_type page.

Warning: Accessing a collection without any filtering attributes, such id_is_{:value}, will return all content items of the content type. If your content type contains more than 50 items, try using filtering attributes as much as possible to prevent this issue.

Bad: this will load all blogs

{% for blog in site.blogs %}
  {% if blog.featured %}
    <div class="featured">{{ blog.title }}</div>
  {% endif %}
{% endfor %}

Good: for content_types with less than 50 items

{% for blog in site.blogs %}
  {{ blog.title }}
{% endfor %}

collection.id_is_{:value}

Returns a single record by id. E.g. site.pages.id_is_1234 returns the post with post_type page and id 1234 and site.content_objects.categories.id_is_1234 does the same for the generic content type categories.

collection.{:content_field}is{:value}

Returns a single record by the value of a content_field. E.g. site.pages.custom_field_is_test_value returns the post with post_type page and with the value of it's content_field custom_field as test_value.

collection'id_in_{:value}, {:value}, …'

Returns multiple records by array of id's. E.g. site.pages['id_in_[1234,9876]'] returns both the posts with post_type page and id 1234 and 9876. Also, site.content_objects.categories['id_in_[1234,9876]'] does the same for the generic content type categories.

collection'{:content_field}in{:value}, {:value}, …'

Returns multiple records by the values of a content_field. E.g. site.pages['custom_field_in_[test_value1,test_value2]'] returns all posts with post_type page and with the value of its content_field custom_field as test_value1 or test_value2. This also works the other way around: if a single value is passed all records containing that value will be returned. E.g. site.pages['custom_field_in_[test_value1]'] will return all posts where the value for custom_field is test_value1

{:content_field}in{:collection}as{:value}

Returns multiple records by the values of a content_field. E.g.

test_value1.referenced_in_pages_as_custom_field returns all posts with post_type page and with the value of it's content_field custom_field as test_value1.


Copyright © 2025