Skip to content

Twig Views Reference

The view adapter provides access to data views — pre-computed, cached queries that aggregate data across collections.

Get the pre-computed data from a data view by its ID.

{% set recentPosts = cms.view.get('recent-posts') %}
{% for post in recentPosts %}
<article>
<h2>{{ post.title }}</h2>
<p>{{ post.excerpt }}</p>
</article>
{% endfor %}
ParameterTypeDescription
viewIdstringData view identifier

Returns: array — the view’s computed result data

Get one page of a data view, filtered and sorted. The view’s output must be a list of objects. It takes the same options as cms.collection.query() and returns the same result: objects, total, limit, offset, page, pages and hasMore.

{% set result = cms.view.query('top-posts', {
filter: [{property: 'score', operator: 'gt', value: 4}],
sort: 'score:desc',
limit: 10,
page: getData.page|default(1)
}) %}
{% for post in result.objects %}
<h2>{{ post.title }}</h2>
{% endfor %}
ParameterTypeDescription
viewIdstringData view identifier
optionsobjectfilter, sort, limit, page or offset, as for cms.collection.query()

The page is cached until the view is rebuilt or any collection is saved. Like get(), it reads the view’s saved output: a view that has not been built yet returns an empty result until its first build. A view whose output is not a list of objects, such as a single stats object, also returns an empty result; use get() for those.

List all available data views.

{% set views = cms.view.list() %}
{% for view in views %}
<p>{{ view.id }} — {{ view.name }}</p>
{% endfor %}

Returns: array — all data view definitions