This documentation describes unreleased changes on the main branch.

post()

Twig function of the framework; its result is escaped like any value.

{{ post(id) }}

The post object of a post, for a post type of this theme or plugin, post or page: an instance of its post class (e.g. an Event), with getters as attributes and meta classes by their #[PostMeta] name. Returns null if the ID is null, the post does not exist, its type has no post class of this theme or plugin, or its status is not public, e.g. a draft (renders for the block editor return posts in every status). The values are escaped like any value; print rich text with |raw.

{% set event = post(postId) %}
{% if event %}
    <h2>{{ event.title }}</h2>
    <p>{{ event.meta('details').capacity }} seats</p>
{% endif %}
ParameterTypeDefaultDescription
idint|nullrequiredID of the post, e.g. from a reference attribute.

Returns ?AbstractPost