Skip to main content
When creating templates, it’s not enough to know only variables, functions, or operators. It is equally important how an expression is processed in the template. The syntax used determines whether an instruction is merely executed, a value is output, or an output is automatically escaped. This distinction is relevant for template development because it has a direct impact on the result produced. Depending on the syntax, a value appears in the HTML, is only processed internally, or is output unchanged. As a result, the syntax determines not only the output itself, but also whether content is output correctly and safely for the respective context. The various forms of instructions therefore help to cleanly control template logic and output. They determine when an expression is merely processed and when its result appears in the generated document. At the same time, they control escaping and thus the handling of special characters, HTML content, or other output contexts. This page describes the available syntax for instructions and shows how they affect processing, output, and escaping.

Instructions overview

SyntaxDescriptionTypical usage
{{ ... }}Executes an instruction without producing output.Setting variables, executing helper logic.
{{= … }}Outputs a value and replaces HTML special characters in the process.Normal output in HTML.
{{! … !}}Outputs a value without replacing HTML special characters.Selectively output already prepared content unchanged.
{{ autoescape "js" }} …
{{ /autoescape }}
Switches the escaping mode within a block.Output in special contexts, e.g., JavaScript

Instructions without output

With {{ ... }}, an instruction is executed without its result being output directly. This syntax is used when something should be prepared or processed in the template without content already appearing in the generated document or page at this point. Typical use cases are setting variables, preparing helper values, or invoking logic whose result is needed only later.

Example

In this example, the product name is stored in a variable. At this point, however, nothing is output yet.
{{ var $myVariableForProductname = $product.name }}

Usage

This syntax makes sense when a value should initially only be processed further or prepared for later output. It should be used when:
  • a variable is being set
  • a value is being cached
  • an instruction only serves the template logic
  • no direct output in the HTML is desired at this point

Output with escaping

With {{= … }}, a value is output and automatically escaped. This syntax is the standard for output in the template when content should appear in the HTML. Single (') and double (") quotes within {{= … }} are equivalent. The difference only affects syntax highlighting in the code editor. Escaping ensures that special characters are not interpreted as HTML. As a result, the output remains correct and content is treated as text.

Example

{{= $product.name }}
If $product.name contains, for example, the value
<b> Tom & Jerry </b>
it becomes, in the HTML output,
&lt;b&gt;Tom &amp; Jerry&lt;/b&gt;
The characters are output in such a way that they are displayed correctly in the browser and are not interpreted as HTML markup.

Usage

This syntax should generally be preferred for normal output in the template. It should be used when:
  • text should be output in the HTML
  • content from variables is being output
  • it is not explicitly desired that HTML be passed through unchanged
  • safe default output is needed
In practice, {{= … }} is the right choice in most cases.

Setting escaping for a range

With autoescape, you can set how outputs should be escaped for a contiguous range. This is particularly relevant when content is not output in the normal HTML context but, for example, within JavaScript.

Example

{{ autoescape "js" }}
    const productName = "{{= $product.name }}";
{{ /autoescape }}
In this example, the escaping mode is set for JavaScript. As a result, outputs within this range are handled appropriately for this context. If $product.name contains the value Damen-Jacke "Alpine", for instance, it becomes "Damen-Jacke \"Alpine\", so that the quotes do not break the JavaScript string.

Usage

This syntax should be used when the output occurs in a special output context for which a different escaping mode is required. This is particularly useful when content is being output within JavaScript, JSON, or comparable contexts.

Output without escaping

With {{! … !}}, a value is output unchanged. No automatic escaping occurs. The output is therefore taken into the generated document exactly as the value is provided. This is only useful if the content should be intentionally output without escaping, for example because it has already been correctly formatted as HTML.

Example

{{! $product.name !}}
If $product.name contains, for example, the value
<b> Tom & Jerry </b>
this content is also passed through as HTML in the HTML output
Tom & Jerry

Usage

This syntax should only be used purposefully and with caution. It should be used when:
  • content is intentionally meant to be output as HTML
  • the value to be output is already correctly prepared
  • no additional escaping should occur
It should not be used when ordinary text is being output. In such cases, {{= … }} is the right choice.