Skip to main content

Template Syntax

Smart Variables renders macro content with a Handlebars-compatible template engine. That means you're not limited to dropping in a single variable like {{page.title}} β€” you can also use Handlebars' block helpers to add conditionals, loops, and formatting logic to your content.

If a variable path doesn't exist (for example, a page with no previousVersion), it silently renders as an empty string instead of showing an error.

Conditionals​

{\{#if}}​

{{#if page.title}}
{{page.title}}
{{/if}}

{\{#if}} … {{else}}​

{{#if page.title}}
{{page.title}}
{{else}}
Untitled page
{{/if}}

{\{#unless}}​

Renders the block only when the value is falsy β€” the inverse of {{#if}}.

{{#unless page.title}}
This page has no title
{{/unless}}

Comparisons inside {\{#if}}​

Handlebars conditionals only check truthiness, so use the built-in eq/ne helpers to compare values:

{{#if (eq page.status "current")}}
This page is current
{{/if}}
{{#if (ne space.type "personal")}}
This is a shared space
{{/if}}

Loops​

{\{#each}}​

Iterate over a list, such as the page's full version history. Inside the block, this refers to the current item.

{{#each page.versions.results}}
Version {{this.number}}: {{this.message}}
{{/each}}

Scoping with {\{#with}}​

{{#with}} changes the context for the block, so you can drop the repeated prefix:

{{#with page.author}}
{{displayName}}
{{/with}}

Comments​

Text inside a comment is not rendered:

{{! this note is not rendered }}

Helper functions​

A small set of helper functions are available for use inside {{ }} expressions or as conditionals:

HelperDescriptionExample
eqReturns true if two values are equal{{#if (eq page.status "current")}}
neReturns true if two values are not equal{{#if (ne page.status "archived")}}
uppercaseConverts a value to upper case{{uppercase page.title}}
lowercaseConverts a value to lower case{{lowercase page.title}}
formatDateFormats an ISO date string{{formatDate page.createdAt "DATE_FULL"}}

formatDate​

formatDate takes the date variable and a format. The format can be a Luxon preset name β€” like DATE_FULL, DATE_SHORT, or DATETIME_FULL β€” or a custom Luxon format token string, such as "yyyy-LL-dd".

{{formatDate page.createdAt "DATE_FULL"}}
{{formatDate page.currentVersion.createdAt "yyyy-LL-dd"}}

An empty or invalid date input renders as an empty string.