String filters change outputs and variables of type string.
append
Appends characters to a string.
{{ 'sales' | append: '.jpg' }}
sales.jpg
base64_encode
Encodes a string to Base64.
{{ 'one two three' | base64_encode }}
b25lIHR3byB0aHJlZQ==
base64_decode
Decodes a string from Base64.
{{ 'b25lIHR3byB0aHJlZQ==' | base64_decode }}
one two three
base64urlsafe_encode
Encodes a string to URL-safe Base64. To create URL-safe Base64, the filter uses - and _ instead of + and /.
{{ '<p>ok?</p>' | base64_url_safe_encode }}
PHA-b2s_PC9wPg==
base64urlsafe_decode
Decodes a string from URL-safe Base64.
{{ 'PHA-b2s_PC9wPg==' | base64_url_safe_decode }}
<p>ok?</p>
camelcase
Converts a string to CamelCase.
{{ 'coming-soon' | camelcase }}
ComingSoon
capitalize
Capitalizes the first word in a string.
{{ 'capitalize me' | capitalize }}
Capitalize me
downcase
Converts a string to lowercase.
{{ 'UPPERCASE' | downcase }}
uppercase
escape
Escapes a string.
{{ "<p>test</p>" | escape }}
<p>test</p>
<!-- Note: a browser shows this as <p>test</p> -->
handleize
Formats a string as a handle. In VersaCommerce the filter is called handleize; there is no short name handle.
The string is converted to lowercase and all spaces and special characters are replaced by hyphens (-). Several consecutive spaces or special characters are replaced by a single hyphen. Spaces and special characters at the start and end are removed.
{{ '100% M & Ms!!!' | handleize }}
100-m-ms
md5
Converts a string to an MD5 hash.
One use of this filter is showing the Gravatar image of the author of a blog comment:
<img src="https://www.gravatar.com/avatar/{{ comment.email | remove: ' ' | strip_newlines | downcase | md5 }}">
<img src="https://www.gravatar.com/avatar/2a95ab7c950db9693c2ceb767784c201">
sha1
Converts a string to a SHA-1 hash.
{% assign my_secret_string = 'VersaCommerceIsAwesome!' | sha1 %}
My encoded string is: {{ my_secret_string }}
My encoded string is: c2dbeca80d33cce5249d4b1448a470e2bee95860
sha256
Converts a string to a SHA-256 hash.
{% assign my_secret_string = 'VersaCommerceIsAwesome!' | sha256 %}
My encoded string is: {{ my_secret_string }}
My encoded string is: db3acf2a3c5295667e95e3761a548abcf22452333517508162aae0b75c39656a
hmac_sha1
Converts a string to a SHA-1 hash with a hash-based message authentication code (HMAC). Pass the secret key for the message as a parameter to the filter.
{% assign my_secret_string = 'VersaCommerceIsAwesome!' | hmac_sha1: 'secret_key' %}
My encoded string is: {{ my_secret_string }}
My encoded string is: eeb5478803ef805b3d4674fb021d600b84a4753c
hmac_sha256
Converts a string to a SHA-256 hash with a hash-based message authentication code (HMAC). Pass the secret key for the message as a parameter to the filter.
{% assign my_secret_string = 'VersaCommerceIsAwesome!' | hmac_sha256: 'secret_key' %}
My encoded string is: {{ my_secret_string }}
My encoded string is: 80f24c762dcf04c7d3ce150c4379cb4dc88688f3fb0ae2598b324e88f56ec47b
newlinetobr
Inserts a <br> line break HTML tag before each line break in a string.
{% capture var %}
One
Two
Three
{% endcapture %}
{{ var | newline_to_br }}
One<br>
Two<br>
Three<br>
pluralize
Outputs the singular or plural form of an English string based on a number. The first parameter is the singular, the second the plural.
pluralize applies English plural rules. Do not use it for strings in other languages, because it produces wrong plurals there.
{{ cart.item_count }}
{{ cart.item_count | pluralize: 'item', 'items' }}
3 items
prepend
Prepends characters to a string.
{{ 'sale' | prepend: 'Made a great ' }}
Made a great sale
remove
Removes all occurrences of a substring from a string.
{{ 'Hello, world. Goodbye, world.' | remove: 'world' }}
Hello, . Goodbye, .
remove_first
Removes only the first occurrence of a substring from a string.
{{ 'Hello, world. Goodbye, world.' | remove_first: 'world' }}
Hello, . Goodbye, world.
replace
Replaces all occurrences of a string with a substring.
<!-- product.title = "Awesome Shoes" -->
{{ product.title | replace: 'Awesome', 'Mega' }}
Mega Shoes
replace_first
Replaces the first occurrence of a string with a substring.
<!-- product.title = "Awesome Awesome Shoes" -->
{{ product.title | replace_first: 'Awesome', 'Mega' }}
Mega Awesome Shoes
slice
slice returns a substring that starts at the given index. An optional second parameter sets the length of the substring. Without a second parameter, a substring of one character is returned.
{{ 'hello' | slice: 0 }}
{{ 'hello' | slice: 1 }}
{{ 'hello' | slice: 1, 3 }}
h
e
ell
If the index is negative, it is counted from the end of the string.
{{ 'hello' | slice: -3, 2 }}
ll
split
split takes a substring as parameter. The substring is used as delimiter to split a string into an array. Use array filters to output parts of the array.
{% assign words = 'Hi, how are you today?' | split: ' ' %}
{% for word in words %}
{{ word }}
{% endfor %}
Hi,
how
are
you
today?
strip
Removes tabs, spaces and line breaks (all whitespace) from the left and right side of a string.
{{ ' too many spaces ' | strip }}
too many spaces
lstrip
Removes tabs, spaces and line breaks (all whitespace) from the left side of a string.
{{ ' too many spaces ' | lstrip }}
too many spaces
rstrip
Removes tabs, spaces and line breaks (all whitespace) from the right side of a string.
{{ ' too many spaces ' | rstrip }}
too many spaces
strip_html
Removes all HTML tags from a string.
{{ '<h1>Hello</h1> World' | strip_html }}
Hello World
strip_newlines
Removes all line breaks from a string.
{{ product.description | strip_newlines }}
truncate
Truncates a string to the number of characters passed as first parameter. An ellipsis (...) is appended to the truncated string and counts towards the number of characters.
{{ 'The cat came back the very next day' | truncate: 13 }}
The cat ca...
Custom ellipsis
truncate takes an optional second parameter with the string to append to the truncated string. By default this is an ellipsis (...), but you can pass another sequence.
The length of the second parameter counts towards the number of characters set by the first parameter. For example, to truncate a string to exactly 10 characters and use a 3-character ellipsis, pass 13 as first parameter, because the ellipsis counts as 3 characters.
{{ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | truncate: 18, ', and so on' }}
ABCDEFG, and so on
No ellipsis
Pass an empty string as second parameter to truncate to the exact number of characters given in the first parameter without trailing characters:
{{ "I'm a little teapot, short and stout." | truncate: 15, '' }}
I'm a little te
truncatewords
Truncates a string to the number of words passed as first parameter. An ellipsis (...) is appended to the truncated string.
{{ 'The cat came back the very next day' | truncatewords: 4 }}
The cat came back...
Custom ellipsis
truncatewords takes an optional second parameter with the string to append to the truncated string. By default this is an ellipsis (...), but you can pass another sequence.
{{ 'The cat came back the very next day' | truncatewords: 4, '--' }}
The cat came back--
No ellipsis
Pass an empty string as second parameter to avoid trailing characters:
{{ 'The cat came back the very next day' | truncatewords: 4, '' }}
The cat came back
upcase
Converts a string to uppercase.
{{ 'i want this to be uppercase' | upcase }}
I WANT THIS TO BE UPPERCASE
url_encode
Converts all URL-unsafe characters in a string to percent-encoded characters.
{{ 'john@liquid.com' | url_encode }}
john%40liquid.com
url_encode converts a space into a + character instead of a percent-encoded character.
{{ 'Jane Doe' | url_encode }}
Jane+Doe
url_escape
Finds all characters in a string that are not allowed in URLs and replaces them with their escaped variants.
{{ '<hello> & <world>' | url_escape }}
%3Chello%3E%20&%20%3Cworld%3E
urlparamescape
Replaces all characters in a string that are not allowed in URLs with their escaped variants, including the ampersand (&).
{{ '<hello> & <world>' | url_param_escape }}
%3Chello%3E%20%26%20%3Cworld%3E
Reversing strings
reverse cannot be applied to a string directly, but you can split a string into an array, reverse the array and join it again by chaining filters:
{{ 'Ground control to Major Tom.' | split: '' | reverse | join: '' }}
.moT rojaM ot lortnoc dnuorG