Build Your Course The Easy Way
Get Started Free

String Filters

String filters are used to manipulate outputs and variables of the `string` type.

In this article:


append

Appends characters to a string.

<h1>{{ current_site_user.name | append: "'s Course Library" }}</h1>

capitalize

Capitalizes the first word in a string.

<p>{{ 'this sentence should be capitalized!' | capitalize }}</p>

downcase

Converts a string into lowercase.

<p>{{ 'CALM DOWN, EVERYTHING IS GOING TO BE ALRIGHT." | downcase }}</p>

upcase

Converts a string into uppercase.

<p>{{ 'wow, that sounds really exciting.' | upcase }}</p>

prepend

Prepends characters to a string.

<h1>{{ current_site.title | prepend: "Welcome to " }}</h1>

remove

Removes all occurrences of a substring from a string.

<p>{{ "Lesson One: The Best Lesson Ever!" | remove: "Lesson" }}</p>

remove_first

Removes only the first occurrence of a substring from a string.

<p>{{ "Lesson One: The Best Lesson Ever!" | remove_first: "Lesson" }}</p>

replace

Replaces all occurrences of a string with a substring.

<p>{{ "Lesson One: The Best Lesson Ever!" | replace: 'Lesson', 'Module' }}</p>

replace_first

Replaces the first occurrence of a string with a substring.

<p>{{ "Lesson One: The Best Lesson Ever!" | replace_first: 'Lesson', 'Module' }}</p>

slice

The slice filter returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring of one character will be returned.

<p>{{ "dysfunctional" | slice: 3, 3 }}</p>

split

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 names = "Ben, Sam, Kenny, Stacy, Kirk" | split: ', ' %} <ul> {% for name in names %} <li>{{ name }}</li> {% endfor %} </ul>

truncate

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.

<p>{{ "I love your cooking blog!" | truncate: 13 }}</p>

truncatewords

Truncates a string down to 'x' words, where x is the number passed as a parameter. An ellipsis (...) is appended to the truncated string.

<p>{{ "I love your cooking blog!" | truncatewords: 4 }}</p>

uniq

Removes any duplicate instances of an element in an array.

{% assign birds = "duck duck duck duck duck duck goose" %} <p>{{ birds | split: ' ' | uniq | join: ', ' }}</p>

Contact support or access our 24/7 Live Chat:

Contact Support Live Chat

Need Help? Live Chat with Us.