Skip to main content

Your First Expression

This page teaches you the five expression patterns that cover most real-world usage.

Step 1: Display a Post Title

The simplest expression outputs a single field:

{{ post.title }}

What you write: {{ post.title }} What visitors see: My Awesome Blog Post

The double curly braces {{ }} tell UnBlock to evaluate the expression and output the result. post.title accesses the current post's title.

Step 2: Format a Date

Call a method with arguments to control output format:

{{ post.date('F j, Y') }}

What you write: {{ post.date('F j, Y') }} What visitors see: January 15, 2024

Arguments go in parentheses after the field name. Here, 'F j, Y' is a PHP date format string.

Step 3: Apply a Filter

Transform data using filters with the pipe (|) operator:

{{ post.title|upper }}

What you write: {{ post.title|upper }} What visitors see: MY AWESOME BLOG POST

Filters go after a | and transform the value on the left. You can chain multiple filters: {{ post.title|lower|slug }}my-awesome-blog-post.

Step 4: Handle Missing Data

Use the fallback operator to provide a default when data is missing:

{{ post.subtitle ?? post.title }}

What you write: {{ post.subtitle ?? post.title }} What visitors see: The subtitle if it exists, otherwise the title.

The ?? (null coalescing) operator returns the left side if it's not null, otherwise the right side. You can chain multiple fallbacks: {{ post.subtitle ?? post.excerpt ?? post.title }}.

Step 5: Conditional Content

Use the ternary operator for if/else logic:

{{ user.logged_in ? 'Welcome back!' : 'Please log in' }}

What you write: {{ user.logged_in ? 'Welcome back!' : 'Please log in' }} What visitors see: Welcome back! if logged in, Please log in otherwise.

The pattern is condition ? value_if_true : value_if_false.

Common mistake

Expressions must be inside {{ }} to produce output. Writing post.title without the braces outputs the literal text "post.title" — not the post's title.

What's next?

You now know the fundamentals: accessing data, methods, filters, fallbacks, and conditionals. These five patterns cover the vast majority of real-world usage.

Expressions not rendering?

If your expressions show as raw text: check your syntax uses {{ }} not { }, and verify the data exists (e.g. the post has a title). Expressions resolve in both the editor and the frontend, but always verify on the frontend — the editor preview is not the source of truth.

  • Expressions & Syntax — Full reference for operators, literals, and advanced features
  • Providers — All available data fields (post, user, site, etc.)
  • Filters — All available filters for transforming data