Skip to documentation content

String Filters

String Filters

Liquid filters for string manipulation (format, split, replace, etc.).

append filter

Add text to the end of the input. If the input is not already a string it will be converted to one using the default behavior for its object type.

append: string text
Example Append textAppend text onto the end of a string
Liquid
{{"fire" | append:"truck"}}
Output
firetruck

capitalize filter

Capitalize words in a string

capitalize
Example Capitalize words in a stringCapitalize all of the words in a sentance
Liquid
{{"a freight train running through the" | capitalize}}
Output
A Freight Train Running Through The

classname filter

Removes all non-alphanumeric characters other than dashes and underscores from a string and replaces them with the separator (or nothing if the separator is empty) to form a valid CSS classname.

classname: string separator
Example Convert text to a classnameThree ways to use the classname filter to convert text into a valid CSS classname
Liquid
{{"a long classname!" | classname-}}<br />
{{-"a long classname!" | classname: "_"-}}<br />
{{-"a long classname!" | classname: ""}}
Output
a-long-classname<br />
a_long_classname<br />
alongclassname

downcase filter

Convert a string to lowercase

downcase
Example Convert a string to lowercaseConvert all characters in a string to lowercase.
Liquid
{{"A Freight TRAIN Running TRHOUGH THE" | downcase}}
Output
a freight train running through the

escape filter

Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: &lt; becomes &amp;lt;)

escape
Example Escape HTML (escape and escape_once)Escape HTML characters for safe output inside other HTML. Use escape for full escaping; use escape_once when content may already be partially escaped to avoid double-encoding.

escape

Liquid
<p title="{{"<p>A string with HTML & other characters</p>" | escape}}">...
Output
<p title="&lt;p&gt;A string with HTML &amp; other characters&lt;/p&gt;">...

Escapes all HTML and special characters.

escape_once

Liquid
<p title="{{"&lt;p&gt;A string with some characters encoded & others not encoded&lt;/p>" | escape_once}}">...
Output
<p title="&lt;p&gt;A string with some characters encoded &amp; others not encoded&lt;/p&gt;">...

Escapes only characters that are not already escaped, avoiding double-encoding.

escape_once filter

Encode a string to be output as HTML, without changing existing escaped entities.

escape_once
Example Escape HTML (escape and escape_once)Escape HTML characters for safe output inside other HTML. Use escape for full escaping; use escape_once when content may already be partially escaped to avoid double-encoding.

escape

Liquid
<p title="{{"<p>A string with HTML & other characters</p>" | escape}}">...
Output
<p title="&lt;p&gt;A string with HTML &amp; other characters&lt;/p&gt;">...

Escapes all HTML and special characters.

escape_once

Liquid
<p title="{{"&lt;p&gt;A string with some characters encoded & others not encoded&lt;/p>" | escape_once}}">...
Output
<p title="&lt;p&gt;A string with some characters encoded &amp; others not encoded&lt;/p&gt;">...

Escapes only characters that are not already escaped, avoiding double-encoding.

DEPRECATED for_json filter

This filter has been deprecated. You should use the json_encode filter instead. Encode a string to be used output as JSON. Unlike json_encode, if the string is null this will return an empty string instead.

for_json
Example Use for_json when serializing to JSON (deprecation note)Use the for_json filter on variables that both do and do not have values
Liquid
{"something": {{'with "value"' | for_json}} }
{"something": {{null | for_json}} }
Output
{"something": "with \"value\""}
{"something": }

The for_json filter works for input with valid values

Liquid
{"something": {{'with "value"' | for_json}} }
Output
{"something": "with \"value\""}

The for_json filter does not produce output if the input is null

Liquid
{"something": {{null | for_json}} }
Output
{"something": }

You can get away with the for_json filter by manually handling null/invalid values

Liquid
{"something": {% if variable is_valid %}{{variable | for_json}}{% else %}null{% endif %} }

The entire for_json filter is deprecated because the json_encode filter handles this and other uses cases more robustly

Liquid
{"something": {{variable | json_encode }} }
Example Json_encode various object typesUse the json_encode filter to format the input for output as json properties. While most usefulf or strings, this can also be used with other object types.
Liquid
{
"null": {{ null | for_json }},
"date": {{ request.date | json_encode }},
"true": {{ true | json_encode }},
"3": {{ 3 | json_encode }},
"-4.2": {{ -4.2 | json_encode }},
"string": {{ 'Liquid is "cool"' | json_encode -}}
}
Output
{
"null": null,
"date": "2009-06-15T13:45:30.0000000Z",
"true": true,
"3": 3,
"-4.2": -4.2,
"string": "Liquid is \"cool\""
}

h filter (alias for escape)

Alias for escape, which encodes a string to be output as HTML. Although "h" is shorter, "escape" is preferred due to its improved readability and maintainability.

h

html_decode filter

Decodes any encoded HTML entities (eg: &amp;lt; becomes &lt;)

html_decode
Example Decode HTML entities in a stringDecode any encoded HTML entities inside a string.
Liquid
{{"&lt;p&gt;A string with HTML &amp; other characters&lt;/p&gt;" | html_decode}}
Output
<p>A string with HTML & other characters</p>

html_encode filter

Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: &lt; becomes &lt;). This is functionally identical to the "escape" filter, though it may be more intuitive in some contexts - such as when using both the html_encode and html_decode filters to execute more advanced string manipulation.

html_encode
Example Encode HTML entities in a stringEncode a string for output inside other HTML markup.
Liquid
<p title="{{"<p>A string with HTML & other characters</p>" | html_encode}}">...
Output
<p title="&lt;p&gt;A string with HTML &amp; other characters&lt;/p&gt;">...

index filter

Returns the 0-based location of the find string in the current string, or -1 if it cannot be found. If start is greater than 0, the search will begin at the specified index. To ignore capitalization, set ignorecase to true.

index: string find, integer start, boolean ignorecase
Example Use the index and last_index filters to find substring positionUse the index and last_index filters on a string to find the position of a substring. index searches forward; last_index searches backward.
Liquid
{% var input = 'ABC About' %}

index: first occurrence

Liquid
{{input | index: 'A'}}
Output
0

index: start after position

Liquid
{{input | index: 'A', 1}}
Output
4

index: substring

Liquid
{{input | index: 'Ab'}}
Output
4

index: with case-insensitive flag

Liquid
{{input | index: 'Ab', 0, true}}
Output
0

index: not found

Liquid
{{input | index: 'D'}}
Output
-1

last_index: last occurrence

Liquid
{{input | last_index: 'A'}}
Output
4

last_index: search backward from position

Liquid
{{input | last_index: 'A', 3}}
Output
0

last_index: substring

Liquid
{{input | last_index: 'AB'}}
Output
0

last_index: with case-insensitive flag

Liquid
{{input | last_index: 'AB', -1, true}}
Output
4

last_index: not found

Liquid
{{input | last_index: 'a'}}
Output
-1

json_decode filter

Decode a json encoded string

json_decode
Example Decode a json encoded stringUse the json_decode filter to decode a json encoded string
Liquid
{{'\"liquid\" filter' | json_decode}}
Output
"liquid" filter

json_encode filter

Encode the input object to be used as a JSON property.

json_encode

Null values output the string &quot;null&quot;. Dates are output using the ISO 8601 standard. Booleans are output as &quot;true&quot; or &quot;false&quot;. Numbers are output as numbers. Strings are output as json encoded strings with quote marks properly escaped.

Example Use for_json when serializing to JSON (deprecation note)Use the for_json filter on variables that both do and do not have values
Liquid
{"something": {{'with "value"' | for_json}} }
{"something": {{null | for_json}} }
Output
{"something": "with \"value\""}
{"something": }

The for_json filter works for input with valid values

Liquid
{"something": {{'with "value"' | for_json}} }
Output
{"something": "with \"value\""}

The for_json filter does not produce output if the input is null

Liquid
{"something": {{null | for_json}} }
Output
{"something": }

You can get away with the for_json filter by manually handling null/invalid values

Liquid
{"something": {% if variable is_valid %}{{variable | for_json}}{% else %}null{% endif %} }

The entire for_json filter is deprecated because the json_encode filter handles this and other uses cases more robustly

Liquid
{"something": {{variable | json_encode }} }
Example Json_encode various object typesUse the json_encode filter to format the input for output as json properties. While most usefulf or strings, this can also be used with other object types.
Liquid
{
"null": {{ null | for_json }},
"date": {{ request.date | json_encode }},
"true": {{ true | json_encode }},
"3": {{ 3 | json_encode }},
"-4.2": {{ -4.2 | json_encode }},
"string": {{ 'Liquid is "cool"' | json_encode -}}
}
Output
{
"null": null,
"date": "2009-06-15T13:45:30.0000000Z",
"true": true,
"3": 3,
"-4.2": -4.2,
"string": "Liquid is \"cool\""
}

last_index filter

Returns the last 0-based location of the last occurrence of find string in the current string, or -1 if it cannot be found. If start is greater than or equal to 0, the search will begin at the specified index. To ignore capitalization, set ignorecase to true.

last_index: string find, integer start, boolean ignorecase
Example Use the index and last_index filters to find substring positionUse the index and last_index filters on a string to find the position of a substring. index searches forward; last_index searches backward.
Liquid
{% var input = 'ABC About' %}

index: first occurrence

Liquid
{{input | index: 'A'}}
Output
0

index: start after position

Liquid
{{input | index: 'A', 1}}
Output
4

index: substring

Liquid
{{input | index: 'Ab'}}
Output
4

index: with case-insensitive flag

Liquid
{{input | index: 'Ab', 0, true}}
Output
0

index: not found

Liquid
{{input | index: 'D'}}
Output
-1

last_index: last occurrence

Liquid
{{input | last_index: 'A'}}
Output
4

last_index: search backward from position

Liquid
{{input | last_index: 'A', 3}}
Output
0

last_index: substring

Liquid
{{input | last_index: 'AB'}}
Output
0

last_index: with case-insensitive flag

Liquid
{{input | last_index: 'AB', -1, true}}
Output
4

last_index: not found

Liquid
{{input | last_index: 'a'}}
Output
-1

lstrip filter

Removes whitespace from the beginning of a string

lstrip
Example Various ways to strip whitespace from strings3 filters to remove whitespace from before and after strings
Liquid
{% var sentence_with_extra_whitespace = ' The quick brown fox jumps over the lazy dog. ' %}
Liquid
[{{sentence_with_extra_whitespace | lstrip}}]
Output
[The quick brown fox jumps over the lazy dog. ]
Liquid
[{{sentence_with_extra_whitespace | rstrip}}]
Output
[ The quick brown fox jumps over the lazy dog.]
Liquid
[{{sentence_with_extra_whitespace | strip}}]
Output
[The quick brown fox jumps over the lazy dog.]

newline_to_br filter

Add &lt;br /&gt; tags in front of all newlines in the current string

newline_to_br
Example Add <br /> in front of all newlines in a stringInsert <br /> (or another tag) before each newline in a string so line breaks show in HTML.
Liquid
{%- capture input -%}
ABC
DEF
GHI
{%- endcapture -%}
{{-input | newline_to_br}}
Output
ABC<br />
DEF<br />
GHI

plus filter

Adds the operand to the current value. Note that this filter behaves differently if the current value is a string

plus: number operand

The plus filter may behave differently when used with string input. When used with a string input it may append text to the current value, although that behavior is deprecated and should be replaced by the append filter for optimal forward-compatibility.

prepend filter

Add text to the beginning of the input. If the input is not already a string it will be converted to one using the default behavior for its object type.

prepend: string text
Example Prepend textPrepend text onto the beginning of a string
Liquid
{{"truck" | prepend:"fire"}}
Output
firetruck

remove filter

Remove all occurrences of search from the current string.

remove: string search
Example Remove text from the input stringUse the remove and remove_first filters to remove a string from another string
Liquid
{% var input = 'apply for apples app development' %}
Liquid
{{input | remove:'app'}}
Output
ly for les  development
Liquid
{{input | remove_first:'app'}}
Output
ly for apples app development
Liquid
{{input | remove_first:'app', 2}}
Output
ly for les app development

The remove and remove_first filters are case-sensitive

Liquid
{{ input | remove:'App' }}
Output
apply for apples app development

remove_first filter

Remove the first occurrence(s) of search from the current string.

remove_first: string search, integer num_replacements
Example Remove text from the input stringUse the remove and remove_first filters to remove a string from another string
Liquid
{% var input = 'apply for apples app development' %}
Liquid
{{input | remove:'app'}}
Output
ly for les  development
Liquid
{{input | remove_first:'app'}}
Output
ly for apples app development
Liquid
{{input | remove_first:'app', 2}}
Output
ly for les app development

The remove and remove_first filters are case-sensitive

Liquid
{{ input | remove:'App' }}
Output
apply for apples app development

replace filter

Replace all occurrences of search inside the current string with replacement

replace: string search, string replacement
Example Replace text in the input stringUse the replace and replace_first filters to replace a string with another string inside the input
Liquid
{% var input = 'apply for apples app development' %}
Liquid
{{input | replace:'app', 'mop'}}
Output
moply for moples mop development
Liquid
{{input | replace_first:'app', 'mop'}}
Output
moply for apples app development
Liquid
{{input | replace_first:'app', 'mop', 2}}
Output
moply for moples app development

The replace and replace_first filters are case-sensitive

Liquid
{{ input | replace:'App', 'Mop'}}
Output
apply for apples app development

replace_first filter

Replace the first occurrence(s) of search inside the current string with replacement

replace_first: string search, string replacement, integer num_replacements
Example Replace text in the input stringUse the replace and replace_first filters to replace a string with another string inside the input
Liquid
{% var input = 'apply for apples app development' %}
Liquid
{{input | replace:'app', 'mop'}}
Output
moply for moples mop development
Liquid
{{input | replace_first:'app', 'mop'}}
Output
moply for apples app development
Liquid
{{input | replace_first:'app', 'mop', 2}}
Output
moply for moples app development

The replace and replace_first filters are case-sensitive

Liquid
{{ input | replace:'App', 'Mop'}}
Output
apply for apples app development

replace_regex filter

Replace all occurrences of pattern inside the current string with replacement using a regular expression - making it possible to search for more complicated expressions and replace using the resulting captured groups.

replace_regex: string pattern, string replacement
Example Replace text in the input string using a regexUse the replace_regex and replace_regex_first filters to use advanced matching logic to replace a string with another string inside the input
Liquid
{% var input = 'The quick brown dog jumps over the lazy dog.' %}
Liquid
{{input | replace_regex:'/dog/i', 'dragon'}}
Output
The quick brown dragon jumps over the lazy dragon.
Liquid
{{input | replace_regex_first:'/dog/i', 'dragon'}}
Output
The quick brown dragon jumps over the lazy dog.
Liquid
{{input | replace_regex_first:'(quick|brown|lazy)', 'adjective:$1', 2}}
Output
The adjective:quick adjective:brown dog jumps over the lazy dog.

replace_regex_first filter

Replace the first occurrence(s) of pattern inside the current string with replacement using a regular expression - making it possible to search for more complicated expressions and replace using the resulting captured groups.

replace_regex_first: string pattern, string replacement, integer num_replacements
Example Replace text in the input string using a regexUse the replace_regex and replace_regex_first filters to use advanced matching logic to replace a string with another string inside the input
Liquid
{% var input = 'The quick brown dog jumps over the lazy dog.' %}
Liquid
{{input | replace_regex:'/dog/i', 'dragon'}}
Output
The quick brown dragon jumps over the lazy dragon.
Liquid
{{input | replace_regex_first:'/dog/i', 'dragon'}}
Output
The quick brown dragon jumps over the lazy dog.
Liquid
{{input | replace_regex_first:'(quick|brown|lazy)', 'adjective:$1', 2}}
Output
The adjective:quick adjective:brown dog jumps over the lazy dog.

reverse filter

Reverses the input string or list.

reverse

When used with a string as input, the result is a string. Otherwise the result is a list.

Example Using the reverse filterUse the reverse filter to reverse either a string or a list

When used on null input

Liquid
{{null | reverse | object_type}}
Output
null

When used on a string

Liquid
{{"string" | reverse}}
Output
gnirts

When used on a list

Liquid
{{"item1,item2,item3" | split:"," | reverse | join:" "}}
Output
item3 item2 item1

rstrip filter

Removes whitespace from the end of a string

rstrip
Example Various ways to strip whitespace from strings3 filters to remove whitespace from before and after strings
Liquid
{% var sentence_with_extra_whitespace = ' The quick brown fox jumps over the lazy dog. ' %}
Liquid
[{{sentence_with_extra_whitespace | lstrip}}]
Output
[The quick brown fox jumps over the lazy dog. ]
Liquid
[{{sentence_with_extra_whitespace | rstrip}}]
Output
[ The quick brown fox jumps over the lazy dog.]
Liquid
[{{sentence_with_extra_whitespace | strip}}]
Output
[The quick brown fox jumps over the lazy dog.]

size filter

Returns the length of the input string or list.

size

If the input is not a string or list returns 0.

Example Using the size filterUse the size filter to get the size of a string or a list

When used on null input

Liquid
{{null | size}}
Output
0

When used on a string

Liquid
{{"string" | size}}
Output
6

When used on a list

Liquid
{{"item1,item2,item3" | split:"," | size}}
Output
3

When used on anything else

Liquid
{{request.date | size}}
Output
0

slice filter

Return a part of the current string or list.

slice: integer start, integer length

If the input is a string this will return a string. If it is a list it will return a list. Otherwise it will not do anything and will return the unaltered input.

Example Using the slice filterUse the slice filter to get a portion of a string or list.

When used on null input

Liquid
{{null | slice | object_type}}
Output
null

When used on a string

Liquid
{{"string" | slice: 2}}
Output
ring
Liquid
{{"string" | slice: 2, 3}}
Output
rin

When used on a list

Liquid
{{"ab,cd,ef,gh,ij,kl,mn,op,qr,st,uv,wx,yz" | split:"," | slice: 2, 3 | join: " "}}
Output
ef gh ij

With a negative start value

Liquid
{{"string" | slice: -2}}
Output
ng

With a negative length

Liquid
{{"string" | slice: 2, -1}}
Output
rin

With a negative start and length

Liquid
{{"string" | slice: -4, -2}}
Output
ri

With length = 0

Liquid
{{"string" | slice: -4, 0}}
Output
ring

With a really large negative start

Liquid
{{"string" | slice: -20}}
Output
string

With start higher than the input length

Liquid
[{{"string" | slice: 20}}]
Output
[]

With a calculated length less or equal to 0

Liquid
[{{"string" | slice: 2, -4}}]
Output
[]

Does not do anything if the object is not a string or a list

Liquid
{{ request.date | slice: 2 }}
Output
9/9/2009 12:00:00 AM

split filter

Split a string into a list of substrings separated by the given separator

split: string separator
Example Using the split filterUse the split filter to convert a string into a list of strings separated by the given separator
Liquid
{{'The quick brown fox jumps over the lazy dog.' | split:" " | json_encode}}
Output
["The","quick","brown","fox","jumps","over","the","lazy","dog."]

Split on multiple characters

Liquid
{{'She sells sea shells on the sea shore.' | split:"sea" | json_encode}}
Output
["She sells "," shells on the "," shore."]

Does not include empty strings in the result

Liquid
{{"110100101" | split:'1' | json_encode}}
Output
["0","00","0" | split:'1'}}

Use an empty pattern to split the string into individual characters

Liquid
{{"abcdef" | split:'' | json_encode}}
Output
["a","b","c","d","e","f"]

strip filter

Removes whitespace from the beginning and end of a string

strip
Example Various ways to strip whitespace from strings3 filters to remove whitespace from before and after strings
Liquid
{% var sentence_with_extra_whitespace = ' The quick brown fox jumps over the lazy dog. ' %}
Liquid
[{{sentence_with_extra_whitespace | lstrip}}]
Output
[The quick brown fox jumps over the lazy dog. ]
Liquid
[{{sentence_with_extra_whitespace | rstrip}}]
Output
[ The quick brown fox jumps over the lazy dog.]
Liquid
[{{sentence_with_extra_whitespace | strip}}]
Output
[The quick brown fox jumps over the lazy dog.]

strip_html filter

Removes all HTML tags from a string and can optionally unescape HTML entities.

strip_html: boolean unescapeHtmlEntities, boolean onlyUnescapeIfHtml

Pass true for unescapeHtmlEntities unless there is a reason to preserve encoded entities. When the input may be either HTML or already plain text, pass true for both arguments so onlyUnescapeIfHtml prevents entity decoding unless the input looks like HTML. Avoid mixing plain text and HTML markup in one value: a mixed value that does not begin like HTML will have its tags removed but keep its entities encoded. This filter uses simple pattern matching to recognize and remove HTML. If the input is poorly formatted or contains unusual character sequences - particularly involving the &#39;&lt;&#39; and &#39;&gt;&#39; characters - this could result in unexpected behavior.

Example Strip HTML from an input stringRemove HTML tags from a string and optionally unescape HTML entities using the strip_html filter.

Default behavior preserves HTML entities

Liquid
{% var input = "<p>This is &gt; that</p>" %}
{{- input | strip_html -}}
Output
This is &gt; that

Both arguments default to false, preserving the filter's previous behavior: HTML tags are removed and HTML entities remain encoded.

Preferred for known HTML

Liquid
{% var input = "<p>This is &gt; that</p>" %}
{{- input | strip_html: true -}}
Output
This is > that

Pass true for unescapeHtmlEntities when the input is known to be HTML. This is the recommended form unless the encoded entities must be preserved.

Conditionally unescape known HTML

Liquid
{{- "<p>This is HTML &amp; characters should be unescaped</p>" | strip_html: true, true -}}
Output
This is HTML & characters should be unescaped

When the input type is uncertain, pass true for both arguments. Because this input looks like HTML, its entities are unescaped after its tags are removed.

Preserve entities in plain text

Liquid
{{- "This is plain text &amp; characters should be unchanged" | strip_html: true, true -}}
Output
This is plain text &amp; characters should be unchanged

Because this input does not look like HTML, onlyUnescapeIfHtml leaves its entities encoded. HTML tags would still be removed if any were present.

Avoid mixed HTML and plain text

Liquid
{{- "This is <strong>MIXED</strong> &amp; characters <em>may</em> be changed" | strip_html: true, true -}}
Output
This is MIXED &amp; characters may be changed

Avoid mixed HTML and plain-text input whenever possible. Because this value begins as plain text, its tags are removed but its entities remain encoded.

Liquid
{%- capture input -%}
<script>... this will strip script blocks ...</script>
<style>... this will also strip style blocks ...</style>
<!-- and this will strip HTML comments -->
<p title="this will strip the open and close tags but leave the content intact">The quick brown fox jumps over the lazy dog.</p>
<br />
<img src="..." alt="note that this will also strip images" />
{%- endcapture -%}
{{-input | strip_html | strip}}
Output
The quick brown fox jumps over the lazy dog.

Could result in unexpected behavior with poorly formatted input

Liquid
{%- capture input -%}
//script outside of a script tag
if (a < b)
  doSomething();
if(a > b)
  doSomethingElse();
//endscript
{%- endcapture -%}
{{-input | strip_html | strip}}
Output
//script outside of a script tag
if (a  b)
  doSomethingElse();
//endscript

Could result in unexpected behavior with poorly formatted input

Liquid
{%- capture input -%}
<p>The following invalid markup contains an unescaped &gt; character in an HTML attribute:
<input type="button" onclick="if(a>b) doSomething();" value="Do Something" /></p>
{%- endcapture -%}
{{-input | strip_html | strip}}
Output
The following invalid markup contains an unescaped &gt; character in an HTML attribute:
b) doSomething();" value="Do Something" />

strip_newlines filter

Removes all newlines from a string

strip_newlines
Example Remove newlines from a string (strip or replace)Use the strip_newlines filter to remove all newlines from a string
Liquid
{%- capture input -%}
ABC
DEF
GHI
{%- endcapture -%}
{{-input | strip_newlines}}
Output
ABCDEFGHI

times filter

Multiply the input by the operand.

times: number operand

This filter currently behaves differently if the input is a string and the operand is an integer. In that case the result is a list of strings with input repeated operand times.

Example Using the times filter with a stringYou can currently use the times to multiply a string into a list of identical strings, although this behavior is deprecated. If you need this functionality you are advised to find a different way to accomplish it.

Current functionality

Liquid
{{"string" | times:2 | json_encode}}
Output
["string","string"]

Future functionality

Liquid
{{"string" | times:2 | json_encode}}
Output
Liquid error

Potential Replacement

Liquid
{%- map string for i in (1..2) %}string{% endmap -%}
{{-string | json_encode}}
Output
["string","string"]

Alternate Replacement

Liquid
{%- capture string %}{% for i in (1..2) %}string{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture -%}
{{-string | split:',' | json_encode}}
Output
["string","string"]

truncate filter

Truncates a string down to length characters. If the original string is longer than length characters, the result will end with truncate_string.

truncate: integer length, string truncate_string
Example Truncating textUse the truncate, truncate_to_word, or truncate_words filter to shorten text to a specific number of characters or words.
Liquid
{% var input = 'The quick brown fox jumps over the lazy dog.' %}

truncate

Liquid
{{input | truncate:33}}
Output
The quick brown fox jumps over...
Liquid
{{input | truncate:33 | size}}
Output
33
Liquid
{{input | truncate:31, " (more)"}}
Output
The quick brown fox jump (more)
Liquid
{{input | truncate:33, ""}}
Output
The quick brown fox jumps over th
Liquid
{{'Shorter than 33 characters' | truncate: 33}}
Output
Shorter than 33 characters

truncate_to_word

Liquid
{{input | truncate_to_word:30}}
Output
The quick brown fox jumps...
Liquid
{{input | truncate_to_word:30 | size}}
Output
28
Liquid
{{input | truncate_to_word:30, false}}
Output
The quick brown fox jumps over...
Liquid
{{input | truncate_to_word:30, false | size}}
Output
33

truncate_words

Liquid
{{input | truncate_words:3}}
Output
The quick brown...
Liquid
{{input | truncate_words:3, " (more)"}}
Output
The quick brown (more)
Liquid
{{input | truncate_words:9}}
Output
The quick brown fox jumps over the lazy dog.

truncate_to_word filter

Truncates a string down to length characters. If the string would be broken in the middle of a word, ensures that the break happens either before or after the word. If the string is truncated it will end with truncate_string.

truncate_to_word: integer length, boolean break_before_word, string truncate_string

The truncate_to_word uses a naive algorithm for word counting that considers words as one or more letters, digits, underscores, or apostrophes. All other characters are considered non-word characters in between words. This means that a string could still be truncated in the middle of a hypenated word or a word with other non-word characters such as &quot;awe-inspiring&quot;, &quot;r&amp;r&quot;, &quot;1.25&quot;, &quot;3/4&quot;, etc.... This filter also does not strip or consolidate whitespace, or handle HTML markup any different than normal text.

Example Truncating textUse the truncate, truncate_to_word, or truncate_words filter to shorten text to a specific number of characters or words.
Liquid
{% var input = 'The quick brown fox jumps over the lazy dog.' %}

truncate

Liquid
{{input | truncate:33}}
Output
The quick brown fox jumps over...
Liquid
{{input | truncate:33 | size}}
Output
33
Liquid
{{input | truncate:31, " (more)"}}
Output
The quick brown fox jump (more)
Liquid
{{input | truncate:33, ""}}
Output
The quick brown fox jumps over th
Liquid
{{'Shorter than 33 characters' | truncate: 33}}
Output
Shorter than 33 characters

truncate_to_word

Liquid
{{input | truncate_to_word:30}}
Output
The quick brown fox jumps...
Liquid
{{input | truncate_to_word:30 | size}}
Output
28
Liquid
{{input | truncate_to_word:30, false}}
Output
The quick brown fox jumps over...
Liquid
{{input | truncate_to_word:30, false | size}}
Output
33

truncate_words

Liquid
{{input | truncate_words:3}}
Output
The quick brown...
Liquid
{{input | truncate_words:3, " (more)"}}
Output
The quick brown (more)
Liquid
{{input | truncate_words:9}}
Output
The quick brown fox jumps over the lazy dog.

truncate_words filter

Truncates the input string down to length words. If the input is longer than length words, appends truncate_string to the end of the truncated string.

truncate_words: integer length, string truncate_string

The truncate_words uses a naive algorithm for word counting that considers words as one or more letters, digits, underscores, or apostrophes. All other characters are considered non-word characters in between words. This means that hyphenated words such as &quot;awe-inspiring&quot; are counted as two words, as are &quot;words&quot; with other characters between letters, such as &quot;r&amp;r&quot;, &quot;1.25&quot;, &quot;3/4&quot;, etc.... This filter also does not strip or consolidate whitespace, or handle HTML markup any different than normal text.

Example Truncating textUse the truncate, truncate_to_word, or truncate_words filter to shorten text to a specific number of characters or words.
Liquid
{% var input = 'The quick brown fox jumps over the lazy dog.' %}

truncate

Liquid
{{input | truncate:33}}
Output
The quick brown fox jumps over...
Liquid
{{input | truncate:33 | size}}
Output
33
Liquid
{{input | truncate:31, " (more)"}}
Output
The quick brown fox jump (more)
Liquid
{{input | truncate:33, ""}}
Output
The quick brown fox jumps over th
Liquid
{{'Shorter than 33 characters' | truncate: 33}}
Output
Shorter than 33 characters

truncate_to_word

Liquid
{{input | truncate_to_word:30}}
Output
The quick brown fox jumps...
Liquid
{{input | truncate_to_word:30 | size}}
Output
28
Liquid
{{input | truncate_to_word:30, false}}
Output
The quick brown fox jumps over...
Liquid
{{input | truncate_to_word:30, false | size}}
Output
33

truncate_words

Liquid
{{input | truncate_words:3}}
Output
The quick brown...
Liquid
{{input | truncate_words:3, " (more)"}}
Output
The quick brown (more)
Liquid
{{input | truncate_words:9}}
Output
The quick brown fox jumps over the lazy dog.

upcase filter

Convert a string to uppercase

upcase
Example Convert a string to uppercaseConvert all characters in a string to uppercase.
Liquid
{{"A Freight TRAIN Running TRHOUGH THE" | upcase}}
Output
A FREIGHT TRAIN RUNNING THROUGH THE

url_decode filter

Decode a url encoded string.

url_decode: boolean formdata
Example Url Encoding and DecodingUse the url_encode and url_decode filters to encode strings for use in URLs, and to decode strings that have been url encoded.

url_encode

Liquid
{{"liquid filter" | url_encode}}
Output
liquid%20filter
Liquid
{{"liquid filter" | url_encode:true}}
Output
liquid+filter

url_decode

Liquid
{{"liquid%20filter" | url_decode}}
Output
liquid filter
Liquid
{{"liquid+filter" | url_decode}}
Output
liquid+filter
Liquid
{{"liquid+filter" | url_decode:true}}
Output
liquid filter

url_encode filter

Encode a string to be used in a URL.

url_encode: boolean formdata
Example Url Encoding and DecodingUse the url_encode and url_decode filters to encode strings for use in URLs, and to decode strings that have been url encoded.

url_encode

Liquid
{{"liquid filter" | url_encode}}
Output
liquid%20filter
Liquid
{{"liquid filter" | url_encode:true}}
Output
liquid+filter

url_decode

Liquid
{{"liquid%20filter" | url_decode}}
Output
liquid filter
Liquid
{{"liquid+filter" | url_decode}}
Output
liquid+filter
Liquid
{{"liquid+filter" | url_decode:true}}
Output
liquid filter