Format - Liquid Tag Reference
On this page
The format tag declares the output format of the content it wraps, which sets how each {{ }} value inside it is escaped or encoded. Outside any format block, values are HTML-escaped.
A feed already encodes values for the format it serves, so a feed template does not need this tag for that format. Use it to override one region, such as a script body, or a fragment you have already built yourself.
Syntax
```liquid
{% format ‘
{% format ‘
| Property | Value |
|---|---|
| Tag Name | format |
| Type | Block tag |
| Source | Hydrofoil (core) |
The format can be a quoted string or a variable, such as the format variable a feed template receives.
Formats
| Format | How {{ }} values are output |
|---|---|
html, xml |
HTML-escaped. This is also what happens with no format block. |
js |
JavaScript-escaped, so a value cannot break out of a script string |
json, jsonl |
JSON-encoded: strings quoted and escaped, numbers and booleans bare, nil as null, a list as a JSON array |
csv |
Escaped as a CSV cell: quoted only when the value contains a comma, double quote, or line break. nil is an empty cell. |
txt, md |
Raw, with no escaping |
Use the short format names in this table, not MIME types. An unrecognized format is HTML-escaped.
With encode: false, values inside the block are output raw, whatever the format.
A nested format block uses the format it declares. The outer format resumes after the inner block closes and does not re-encode the inner output.
Examples
Escape values for a script inside an HTML page:
```liquid
```
Emit a fragment you have already built as JSON, without encoding it again:
```liquid
{%- new Map extra -%} {%- assign extra = extra | set_key: “source”, “storeconnect” -%} {%- assign extra_json = extra | json -%} {% format ‘txt’, encode: false %}{{ extra_json }}{% endformat %} ```
Security
The format tag works in every template, not only feeds. A raw block (txt, md, or encode: false) turns off HTML-escaping for every value inside it. Never wrap customer-entered data in a raw block on an HTML page, because that removes the protection against cross-site scripting.
Was this article helpful?
Thanks for your feedback! It helps us improve our docs.