Get and Set

The Get and Set tags are useful for remembering a value to use later, or in multiple places.

This is commonly called a "variable", which has a unique name and holds a reference to a value.

Set

Use the Set tag by giving it a name where to save the value.

In the example below, the current post ID is stored in a variable called current_id.

<Set name=current_id>
  <Field id />
</Set>

Get

Use the Get tag with a variable name to get the value.

<Get name=current_id />

Variable types

In addition to regular variables, there are other variable types with special behavior.

These can be accessed by using an attribute name of the variable type, instead of the name attribute.

For example, to get the site URL:

<Get url=site />

Most of the variable types have a tag as a shortcut. The above is equivalent to:

<Url site />

For details, see the page for each variable type.

Template variable

The template variable type is useful for storing templates, then rendering them later, or in multiple places.

This is in contrast to regular variables, which are rendered upon setting them.

For example, to create a reusable template:

<Set template=title_and_content>
  <h1><Field title /></h1>
  <Field content />
</Set>

It can be used anywhere, such as inside a loop.

<Loop type=page count=1>
  <Get template=title_and_content />
</Loop>

Local variable

A local variable only exists within a template post or file.

Use the local attribute to set and get local variables.

<Set local=variable_name>..</Set>

<Get local=variable_name/>

Local variables are useful for templates that you plan to share with other people, to make sure the template doesn't change variables used outside of it.

JS variable

This is a way to pass values to the Script section of a template post.

<Set js=variable_name>..</Set>

A valid variable name must include only alphanumeric (letters and numbers) and underscore _. It cannot include a dash -.

By default, the value is wrapped in "quotes" to create a string. Use the type attribute for other value types: number, array (or list), object (or map), and raw. (These all work the same by passing unquoted value.)

Sass variable

This is a way to pass values to the Style section of a template post.

<Set sass=variable_name>..</Set>

A valid variable name must include only alphanumeric (letters and numbers), underscore _, and dash -.

By default, the value is wrapped in "quotes" to create a string. Use the type attribute for other value types: number, color, list, map, and raw. (These all work the same by passing unquoted value.)