Skip to documentation content

The Entity Object and Entity-Driven Pages

The Entity Object and Entity-Driven Pages

What the entity object is, that it is always on the root scope, and how to use it in pages and partials.

The entity object is the page’s primary content record: the article, blog post, form, folder, or other type that this URL is about. It is one of the reserved root-scope variables, always set on every page (with request, site, and the rest). Templates cannot assign a different value to the name entity.

You do not need {% if entity is_valid %} (or a similar guard) before {{ entity }}, {{ entity.title }}, {{ entity.has_url }}, or other root entity properties. Root entity is always valid, so that test is always true and the guard is dead code. Output them directly. Use object_type when you need to branch on what kind of entity the page is.

You do need a guard on other variables, including a copy of entity passed into a partial under another name. For example {% include '/sections/item_content.liquid' item:entity %} and then, in that section, {% if item.is_valid %} … {% endif %}. Optional fields on entity still need is_valid or default; that is a check on the field, not on entity itself.

You can output entity properties, use them in filters and methods, and pass entity into included templates. For shared properties, {{ entities }}, and {% entities %}, see Entity under Content. For branching on type, see the linked example. Common Template Patterns covers the page-vs-partial guard pattern.
Example Check entity or value type with if and object_typeUse if/elsif with object_type or type checks to branch on entity or value type.
Liquid
{%- if entity.object_type == 'tag' -%}
	I am a tag
{%- elsif entity.object_type == 'author' -%}
	I am an author
{%- elsif entity.object_type == 'folder' -%}
	I am a folder
{%- else -%}
	What am I?
{%- endif -%}