FeaturesAPIs & Automation

Run the expensive query once, not on every request

A Data View is a Twig definition that builds a data structure, stored as JSON and rebuilt when the collections it reads from change. Templates fetch the finished result.

Pro Included in Pro

The Shop and journal stats view: Blog and Coffees as collection dependencies, and a Twig definition that counts posts by author and coffees by origin.
The Shop and journal stats view: Blog and Coffees as collection dependencies, and a Twig definition that counts posts by author and coffees by origin.

A Data View does the counting, filtering and joining once instead of on every page load. Templates read the stored JSON with a single cms.view.get('view-id') call.

Written in Twig

  • A definition. A view is a Twig template, called its definition, with the full CMS context: cms.collection.objects(), cms.collection.search() and everything else a page template uses. It sets a data variable, serialized to JSON when the view is built.
  • Joins, not just counts. The obvious use is a dashboard number; the more valuable one is a join. Team members carry a department id and departments live in their own collection: a view walks both once and stores members with their department names attached, so templates loop over a plain array.

Rebuilds that look after themselves

  • Collection dependencies. Any create, update or delete in a collection listed under Dependencies queues the view for rebuild through the job queue, so the queue must be processing for automatic rebuilds.
  • Views that read views. List them under View Dependencies and Total CMS orders the rebuilds and gives the downstream view the upstream one's collection dependencies, so you do not repeat them.
  • Test Run and Rebuild View. Test Run executes a definition without saving and shows the JSON output or the Twig error; Rebuild View runs one by hand.
  • A failed build breaks nothing. The previous data is kept so templates keep rendering, the error is logged, and a red indicator appears next to the view's name.

Who can reach a view

  • Pro, plus a permission. Data Views need the Pro edition or higher and the dataviews permission from Access Groups; both gates have to pass. Without the permission, users cannot see or manage views at all.
  • Agents pass a narrower gate. MCP exposure is set by the view's own mcp.access field, not by access groups. Leave it at the default admin unless the output is genuinely safe for every caller at the tier you choose.

In practice

What it looks like in a template

twig
{# The definition: build a data variable #}
{% set posts = cms.collection.objects('blog') %}
{% set products = cms.collection.objects('products') %}

{% set data = {
    "blog": {
        "total": posts|length,
        "published": posts|filter(p => not p.draft)|length
    },
    "products": {
        "total": products|length,
        "featured": products|filter(p => p.featured)|length
    }
} %}

{# In any template: read the pre-computed result #}
{% set stats = cms.view.get('dashboard-stats') %}
{{ stats.blog.published }} published posts

The definition runs when the view is built; the template only reads stored JSON, however many collections went into it.

At a glance

What you get

Written in Twig you already know
The definition is a template with full CMS context. Set a data variable; Total CMS stores it as JSON and hands it back on demand.
Rebuilds when its data changes
List the collections a view depends on and any create, update or delete queues a rebuild through the job queue. No manual invalidation.
Views can build on views
List other views under View Dependencies and Total CMS orders the rebuilds and inherits their collection dependencies. Cycles are detected and logged.
Test before you save
The Test Run button executes a definition without storing anything, showing the JSON output or the exact Twig error.
A failed build never breaks a page
If a rebuild fails, the previous data is kept and templates keep working. The error is logged and flagged with a red indicator in the admin.

Data Views

Common questions

When does a view rebuild?

When any object in a collection listed under Dependencies is created, updated or deleted, the view is queued for rebuild through the job queue — so the queue has to be running. You can also rebuild manually from the admin at any time.

What if I don't set dependencies?

The view still works, but it will only rebuild when you trigger it manually. Set the dependencies to match the collections your definition actually reads, or list an upstream view under View Dependencies and inherit its collections.

Who can see a Data View?

Data Views need Pro or higher, and access is granted per user through Access Groups with the dataviews permission. MCP exposure is separate and narrower: a view surfaced to agents is governed by its own mcp.access field, which defaults to admin.

Can a view read another view?

Yes, with cms.view.get inside the definition. List the upstream view under View Dependencies so the build order is right and its collection dependencies are inherited. Two views listing each other is a cycle — detected at rebuild time, logged, and best avoided.

Try it on a site of your own.

45 days, every Pro feature, no credit card. Build it, hand it to a client, and see what they can and can’t touch.