String filters are used to modify the output of strings.
Appends characters to a string.
{{ 'sales' | append: '.jpg' }}
sales.jpg
Capitalizes the first word in a string.
{{ 'capitalize me' | capitalize }}
Capitalize me
Converts a string into lowercase.
{{ 'UPPERCASE' | downcase }}
uppercase
Escapes a string.
{{ "<p>test</p>" | escape }}
<!-- The <p> tags are not rendered -->
<p>test</p>
Inserts a <br>
linebreak HTML tag in front of each line break in a string.
{% capture var %}
One
Two
Three
{% endcapture %}
{{ var | newline_to_br }}
One <br>
Two <br>
Three <br>
Prepends characters to a string.
{{ 'sale' | prepend: 'Made a great ' }}
Made a great sale
Removes all occurrences of a substring from a string.
{{ "Hello, world. Goodbye, world." | remove: "world" }}
Hello, . Goodbye, .
Removes only the first occurrence of a substring from a string.
{{ "Hello, world. Goodbye, world." | remove_first: "world" }}
Hello, . Goodbye, world.
Replaces all occurrences of a string with a substring.
<!-- amenity.title = "Awesome Swimming Pool" -->
{{ amenity.title | replace: 'Awesome', 'Huge' }}
Huge Swimming Pool
Replaces the first occurrence of a string with a substring.
<!-- product.title = "Awesome Awesome Swimming Pool" -->
{{ product.title | replace_first: 'Awesome', 'Huge' }}
Huge Awesome Swimming Pool
The split
filter takes on a substring as a parameter. The substring is used as a delimiter to divide a string into an array. You can output different parts of an array using array filters.
{% assign words = "Hi, how are you today?" | split: ' ' %}
{% for word in words %}
{{ word }}
{% endfor %}
Hi,
how
are
you
today?
Strips all HTML tags from a string.
{{ "<h1>Hello</h1> World" | strip_html }}
Hello World
Removes any line breaks/newlines from a string.
{{ rental.description | strip_newlines }}
Truncates a string down to ‘x’ characters, where x is the number passed as a parameter. An ellipsis (…) is appended to the string and is included in the character count.
{{ "The cat came back the very next day" | truncate: 10 }}
The cat...
Truncates a string down to ‘x’ words, where x is the number passed as a parameter. An ellipsis (…) is appended to the truncated string.
{{ "The cat came back the very next day" | truncatewords: 4 }}
The cat came back...
Converts a string into uppercase.
{{ 'i want this to be uppercase' | upcase }}
I WANT THIS TO BE UPPERCASE