Skip to main content

Dynamic Data

Dynamic data lets you display live WordPress content — post titles, user names, dates, custom fields — directly in your templates. You write expressions like {{ post.title }}, and visitors see the actual content.

Familiar syntax

Unblock uses Twig expression syntax, and its providers are modeled after Timber. If you've used either, you already know most of this. If you haven't — no worries, expressions read like plain English: {{ post.title }} does exactly what it looks like.

How expressions work

Expressions are wrapped in double curly braces {{ }}. Inside, you access data through providers, transform it with filters using the pipe | operator, and call functions directly.

{{ post.title }}                   {# Access data #}
{{ post.title|upper }} {# Transform with a filter #}
{{ post.date('F j, Y') }} {# Call a method with arguments #}
{{ post.subtitle ?? post.title }} {# Fallback if null #}
{{ get_post(42).title }} {# Call a function #}

Providers

Providers are the variables you use to access data. Which ones are available depends on the page context.

Root providers

These are directly available in your expressions:

ProviderAvailable onDescription
postSingle posts/pages, loopsCurrent post or loop item
userAll pagesCurrent logged-in visitor
siteAll pagesGlobal site settings and URLs
termTerm archives, term loopsCurrent taxonomy term
archiveArchives, searchArchive title and type
requestAll pagesURL parameters and referrer

Chained providers

These are not root variables — you reach them by chaining from another provider:

ProviderAccessed viaDescription
Authorpost.author, authorSame fields as user, different person
Imagepost.thumbnail, site.iconImage URL, dimensions, alt text
AttachmentLoop over attachmentsFile info for non-image attachments

author is a convenience shortcut — on a single post it resolves to the post's author, on an author archive to the queried author. It uses the same User provider.

{{ post.author.name }}              {# User provider via post #}
{{ author.name }} {# Shortcut — same person as post.author #}
{{ post.thumbnail.src('large') }} {# Image provider via post #}
{{ site.icon.src }} {# Image provider via site #}

Context detection

Unblock automatically provides the right data based on the page type:

Page typeAvailable providers
Single post/pagepost, user, site, request + author shortcut
Term archiveterm, archive, user, site, request
Author archivearchive, user, site, request + author shortcut
Search resultsarchive, user, site, request

Inside a Loop block, the loop variable (e.g. post, term) resolves to the current item, not the page-level context.

Quick examples

{# Post data #}
{{ post.title }}
{{ post.excerpt }}
{{ post.thumbnail.src('large') }}
{{ post.author.name }}
{{ post.date('F j, Y') }}

{# User data #}
{{ user.id ? 'Welcome!' : 'Please log in' }}

{# Fallbacks #}
{{ post.subtitle ?? post.title }}
{{ post.meta('image') ?? '/default.jpg' }}

Lazy evaluation

Expressions are evaluated on-demand. When you write {{ post.subtitle ?? post.title }}, the title is only fetched if the subtitle is null. Branches that are never reached don't trigger any queries.

Next steps