Instructions overview
| Syntax | Description | Typical 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.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 contains, for example, the value
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
{{= … }} is the right choice in most cases.
Setting escaping for a range
Withautoescape, 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
$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 contains, for example, the value
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
{{= … }} is the right choice.