Skip to documentation content

Utilities

Utilities

Comment, literal, and raw helpers for template text and escaping.

{% comment %}

All content between {% comment %} and {% endcomment %} will be ignored. It will not be evaluated or output to the template.

{% comment [name] %}
Parameters
name optionalvariable
Use the name to allow nested comments to also be ignored. If included, the comment will not be closed until an endcomment with the matching name is found.
{% endcomment [name] %}
Parameters
name optionalstring
Must exactly match the name from the {% comment %} method. If the {% comment %} method does not include a name then the {% endcomment %} method must also not include a name.

The comment method is primarily used for one of two purposes: For a developer to leave notes behind so that when they or another developer looks at the code later they understand what it is doing, or to temporarily remove a block of code from a template so that it is no longer evaluated but is easy to add back later. This is particularly helpful when troubleshooting a template error.

Example Use the comment tag to exclude markup from outputWrap content in comment tags so it is not rendered.
Liquid
{%- comment %}
<p>This text will not be output</p>
{% endcomment -%}

{% literal %}

Treats enclosed content as plain text without Liquid parsing, which means that the any liquid markup before the matching {% endliteral %} will NOT be evaluated but will be output directly to the template instead.

{% literal %}
{% endliteral %}

This method creates a new liquid context for storing and manipulating variables.

Example Literal tagUse the literal tag to output Liquid-like syntax as plain text so it is not executed.
Liquid
<script id="mustache_template" type="text/template">{% literal -%}
	{{- object.name }} is {{ object.age }} years old
{%- endliteral %}</script>

{% raw %}

Treats enclosed content as plain text without Liquid parsing. Alternative version of the {% literal %} method.

{% raw %}
{% endraw %}

This method creates a new liquid context for storing and manipulating variables.

Example Output content without Liquid parsing (raw tag)Use the raw tag so Liquid does not interpret curly braces or percent signs inside (e.g. for templates or JS).
Liquid
<script id="mustache_template" type="text/template">{% raw -%}
	{{- object.name }} is {{ object.age }} years old
{%- endraw %}</script>