Skip to main content

String

String filters modify strings.

append​

string | append: string
returns  string

Adds a given string to the end of a string.

Code
{{ shop.url | append: product.url }}
Data
{
"product": {
"url": "/products/reverse-short-sleeve-tee"
}
}
Output
https://shop.myshoplaza.com/products/reverse-short-sleeve-tee

camelcase​

string | camelcase
returns  string

Converts a string to CamelCase.

Code
{{ 'camel-case' | camelcase }}
Output
CamelCase

capitalize​

string | capitalize
returns  string

Capitalizes every word in a string.

Code
{{ 'this sentence should start with a capitalized word.' | capitalize }}
Output
This Sentence Should Start With A Capitalized Word.

downcase​

string | downcase
returns  string

Converts a string to all lowercase characters.

Code
{{ product.title | downcase }}
Data
{
"product": {
"title": "Ace Cashmere Beanie"
}
}
Output
ace cashmere beanie

escape​

string | escape
returns  string

Escapes special characters in HTML, such as <>, ', ", and &, and converts characters into escape sequences. The filter doesn't affect characters within the string that don’t have a corresponding escape sequence.

Code
{{ '<p>Text to be escaped.</p>' | escape }}
Output
&lt;p&gt;Text to be escaped.&lt;/p&gt;

escape_once​

string | escape_once
returns  string

Escapes a string without changing characters that have already been escaped.

Code
{% assign escaped_text = '<p>Text to be escaped.</p>' | escape %}

{{ escaped_text }}
{{ escaped_text | escape_once }}
Output
&lt;p&gt;Text to be escaped.&lt;/p&gt;
&lt;p&gt;Text to be escaped.&lt;/p&gt;

handleize​

string | handleize
returns  string

Converts a string into a handle.

note

The handleize filter has an alias of handle.

Code
{{ product.title | handleize }}
{{ product.title | handle }}
Data
{
"product": {
"title": "Ace Cashmere Beanie"
}
}
Output
ace-cashmere-beanie
ace-cashmere-beanie

hmac_sha1​

string | hmac_sha1: string
returns  string

Converts a string into an SHA-1 hash using a hash message authentication code (HMAC).

The secret key for the message is supplied as a parameter to the filter.

Code
{{ 'Ace' | hmac_sha1: 'Salty' }}
Output
5da24ef75f6a8fc7d28c0fcc7236244d29a4511d

hmac_sha256​

string | hmac_sha256: string
returns  string

Converts a string into an SHA-256 hash using a hash message authentication code (HMAC).

The secret key for the message is supplied as a parameter to the filter.

Code
{{ 'Ace' | hmac_sha256: 'Salty' }}
Output
8f688efb30c4e26bed3e14923030f9276e463e7933c88fc18c0ff0c934185418

lstrip​

string | lstrip
returns  string

Strips all whitespace from the left of a string.

Code
{% assign text = ' Some fruits create whitespace. ' %}
"{{ text }}"
"{{ text | lstrip }}"
Output
" Some fruits create whitespace. "
"Some fruits create whitespace. "

md5​

string | md5
returns  string

Converts a string into an MD5 hash.

Code
{{ '' | md5 }}
Output
d41d8cd98f00b204e9800998ecf8427e

newline_to_br​

string | newline_to_br
returns  string

Converts newlines (\n) in a string to HTML line breaks (<br>).

Code
{% capture description %}
<h3>Sound inspired</h3>
<div>Get inspired with Solo Pro wireless headphones.</div>
{% endcapture %}

{{ description | newline_to_br }}
Output
<br>
<h3>Sound inspired</h3>
<br>
<div>Get inspired with Solo Pro wireless headphones.</div>
<br>

pluralize​

number | pluralize: string, string
returns  string

Outputs the singular or plural version of a string based on a given number.

Code
{% assign item_count = cart.cart %}

Cart item count: {{ item_count }} {{ item_count | pluralize: 'item', 'items' }}
Data
{
"cart": {
"item_count": 2
}
}
Output
Cart item count: 2 items

prepend​

string | prepend: string
returns  string

Adds a given string to the beginning of a string.

Code
{{ product.url | prepend: shop.url }}
Data
{
"product": {
"url": "/products/reverse-short-sleeve-tee"
}
}
Output
https://shop.myshoplaza.com/products/reverse-short-sleeve-tee

remove​

string | remove: string
returns  string

Removes any instance of a substring inside a string.

Code
{{ "I can't do it!" | remove: "'t" }}
Output
I can do it!

remove_first​

string | remove_first: string
returns  string

Removes the first instance of a substring inside a string.

Code
{{ "I don't know why, but I don't know how to do it." | remove_first: "don't" }}
Output
I know why, but I don't know how to do it.

replace​

string | replace: string, string
returns  string

Replaces any instance of a substring inside a string with a given string.

Code
{{ product.handle | replace: '-', ' ' }}
Data
{
"product": {
"handle": "ace-cashmere-beanie"
}
}
Output
ace cashmere beanie

replace_first​

string | replace_first: string, string
returns  string

Replaces the first instance of a substring inside a string with a given string.

Code
{{ product.handle | replace_first: '-', ' ' }}
Data
{
"product": {
"handle": "ace-cashmere-beanie"
}
}
Output
ace cashmere-beanie

rstrip​

string | rstrip
returns  string

Strips all whitespace from the right of a string.

Code
{% assign text = ' Some fruits create whitespace. ' %}
"{{ text }}"
"{{ text | rstrip }}"
Output
" Some fruits create whitespace. "
" Some fruits create whitespace."

sha1​

string | sha1
returns  string

Converts a string into an SHA-1 hash.

Code
{{ 'Ace' | sha1 }}
Output
fc2b5a9cb80ab0a1526f4fbc887646dd245632c2

sha256​

string | sha256
returns  string

Converts a string into an SHA-256 hash.

Code
{{ 'Ace' | sha256 }}
Output
a467da82da540f56097b7224d81612bfa212e26efbf0709606144fee0b82a631

slice​

string | slice
returns  string

Returns a substring or series of array items, starting at a given 0-based index.

By default, the substring has a length of one character, and the array series has one array item. However, you can provide a second parameter to specify the number of characters or array items.

Code
{{ collection.title | slice: 0 }}
{{ collection.title | slice: 0, 3 }}
{{ collection.tags | slice: 1, 2 | join: ', ' }}
Data
{
"collection": {
"tags": [
"Burning",
"fresh",
"music",
"plant",
"Salty"
],
"title": "All products"
}
}
Output
All products
All
fresh, music

Negative index​

You can supply a negative index which will count from the end of the string.

Code
{{ title | slice: -8, 8 }}
Data
{
"collection": {
"title": "All products"
}
}
Output
products

split​

string | split: string
returns  string

Splits a string into an array of substrings based on a given separator.

Code
{% assign title_words = product.handle | split: '-' %}

{% for word in title_words %}
{{ word }}
{% endfor %}
Data
{
"product": {
"handle": "ace-cashmere-beanie"
}
}
Output
ace
cashmere
beanie

strip​

string | strip
returns  string

Strips all whitespace from the left and right of a string.

Code
{% assign text = ' Some fruits create whitespace. ' %}
"{{ text }}"
"{{ text | strip }}"
Output
" Some fruits create whitespace. "
"Some fruits create whitespace."

strip_html​

string | strip_html
returns  string

Strips all HTML tags from a string.

Code
<!-- With HTML -->
{{ product.description }}

<!-- HTML stripped -->
{{ product.description | strip_html }}
Data
{
"product": {
"description": "<h3>Sound inspired</h3>\n<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>"
}
}
Output
<!-- With HTML -->
<h3>Sound inspired</h3>
<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>

<!-- HTML stripped -->
Sound inspired
Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.

strip_newlines​

string | strip_newlines
returns  string

Strips all newline characters (line breaks) from a string.

Code
<!-- With newlines -->
{{ product.description }}

<!-- Newlines stripped -->
{{ product.description | strip_newlines }}
Data
{
"product": {
"description": "<h3>Sound inspired</h3>\n<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>"
}
}
Output
<!-- With newlines -->
<h3>Sound inspired</h3>
<div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>

<!-- Newlines stripped -->
<h3>Sound inspired</h3><div>Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode.</div>

truncate​

string | truncate: number
returns  string

Truncates a string down to a given number of characters.

If the specified number of characters is less than the length of the string, then an ellipsis (...) is appended to the truncated string. The ellipsis is included in the character count of the truncated string.

Code
{{ product.title | truncate: 10 }}
{{ product.title | truncate: 20 }}
Data
{
"product": {
"title": "Ace Cashmere Beanie"
}
}
Output
Ace Cas...
Ace Cashmere Beanie

Specify a custom ellipsis​

string | truncate: number, string

You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.

Code
{{ product.title | truncate: 10, '' }}
{{ product.title | truncate: 10, '···' }}
Data
{
"product": {
"title": "Ace Cashmere Beanie"
}
}
Output
Ace Cashme
Ace ···

truncatebytes​

string | truncatebytes: number
returns  string

Truncates a string down to a given number of bytes.

If the specified number of characters is less than the length of the string, then an ellipsis (...) is appended to the truncated string. The ellipsis is included in the character count of the truncated string.

Code
{{ product.description | truncatebytes: 50 }}
Data
{
"product": {
"description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
}
}
Output
Get inspired with Solo Pro wireless headphones....

Specify a custom ellipsis​

string | truncatebytes: number, string

You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.

Code
{{ product.description | truncatebytes: 50, '' }}
{{ product.description | truncatebytes: 50, '···' }}
Data
{
"product": {
"description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
}
}
Output
Get inspired with Solo Pro wireless headphones. To
Get inspired with Solo Pro wireless headphon···

truncatewords​

string | truncatewords: number
returns  string

Truncates a string down to a given number of words.

If the specified number of words is less than the number of words in the string, then an ellipsis (...) is appended to the truncated string.

Code
{{ product.description | truncatewords: 10 }}
Data
{
"product": {
"description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
}
}
Output
Get inspired with Solo Pro wireless headphones. To deliver sound...

Specify a custom ellipsis​

string | truncatewords: number, string
returns  string

You can provide a second parameter to specify a custom ellipsis. If you don't want an ellipsis, then you can supply an empty string.

Code
{{ product.description | truncatewords: 10, '' }}
{{ product.description | truncatewords: 10, '---' }}
Data
{
"product": {
"description": "Get inspired with Solo Pro wireless headphones. To deliver sound how you want it, Solo Pro features two listening modes: Active Noise Cancelling (ANC) and Transparency mode. Beats’ Pure ANC gives you the space to create with fully immersive sound, while Transparency mode helps you stay aware of your surroundings. Every detail of Solo Pro has been carefully considered, right down to the intuitive way the headphones turn on and off via folding. The ergonomic design delivers exceptional comfort for extended wear and sleek style. And with up to 22 hours of battery life, you can keep the music going no matter where your day takes you."
}
}
Output
Get inspired with Solo Pro wireless headphones. To deliver sound
Get inspired with Solo Pro wireless headphones. To deliver sound---

upcase​

string | upcase
returns  string

Converts a string to all uppercase characters.

Code
{{ product.title | upcase }}
Data
{
"product": {
"title": "Ace Cashmere Beanie"
}
}
Output
ACE CASHMERE BEANIE

url_decode​

string | url_decode
returns  string

Decodes any percent-encoded characters in a string.

Code
{{ 'https%3A%2F%2Fwww.shoplazza.com%2F' | url_decode }}
Output
https://www.shoplazza.com/

url_encode​

string | url_encode
returns  string

Converts any URL-unsafe characters in a string to the percent-encoded equivalent.

note

Spaces are converted to a + character, instead of a percent-encoded character.

Code
{{ 'https://www.shoplazza.com/' | url_encode }}
Output
https%3A%2F%2Fwww.shoplazza.com%2F