String Filters
String filters manipulate strings.
append
Appends a string to the end of another string.
{{ 'filename' | append: '.js' }}
filename.js
capitalize
capitalizes the first word in a string.
{{ 'capitalize me' | capitalize }}
Capitalize Me
downcase
Converts a string into lowercase.
{{ 'MIxed Case TExt' | downcase }}
mixed case text
escape
HTML-escapes a string.
{{ '<p>test</p>' | escape }}
<p>test</p>
newline_to_br
Inserts a <br />
linebreak HTML tag at each line break in a string.
{% capture text %}
A
B
C
{% endcapture %}
{{ text | newline_to_br }}
A<br />
B<br />
C<br />
prepend
Prepends a string to the beginning of another string.
{{ 'Jane Johnson' | prepend: 'Dr. ' }}
Dr. Jane Johnson
remove
Remove all occurrences of a substring from a string.
{{ 'Hello, Dave. How are you, Dave?' | remove: 'Dave' }}
Hello, . How are you, ?
remove_first
Removes the first occurrence of a substring from a string.
{{ 'Hello, Dave. How are you, Dave?' | remove_first: 'Dave' }}
Hello, . How are you, Dave?
replace
Replaces all occurrences of a string with a substring.
{{ 'Hello, Dave. How are you, Dave?' | replace: 'Dave', 'John' }}
Hello, John. How are you, John?
replace_first
Replaces the first occurrence of a string with a substring.
{{ 'Hello, Dave. How are you, Dave?' | replace_first: 'Dave', 'John' }}
Hello, John. How are you, Dave?
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.
{% assign words = "This is a demo of the split filter" | split: ' ' %}
First word: {{ words.first }}
First word: {{ words[0] }}
Second word: {{ words[1] }}
Last word: {{ words.last }}
All words: {{ words | join: ', ' }}
First word: This
First word: This
Second word: is
Last word: filter
All words: This, is, a, demo, of, the, split, filter
strip_html
Strips all HTML tags from a string.
<p>Hello</p>
Hello
strip_newlines
Strips any line breaks from a string.
{% capture text %}
A
B
C
{% endcapture %}
{{ text | strip_newlines }}
ABC
text_to_html
Formats a plain text string as simple HTML. All text will be HTML encoded, blocks of text separated by a blank line will be wrapped in paragraph <p>
tags, single line breaks will be replaced with <br>
, and URLs will be converted to hyperlinks.
{{ note.notetext | text_to_html }}
<p>This is the first paragraph of notetext. It contains a URL: <a href="http://example.com/" rel="nofollow">http://example.com</a></p>
<p>This is a second paragraph.</p>
truncate
Truncates a string down to a given number of characters. An ellipsis (...) is appended to the string and is included in the character count.
{{ 'This is a long run of text.' | truncate: 10 }}
This is...
truncate_words
Truncates a string down to a given number of words. An ellipsis (...) is appended to the truncated string.
{{ 'This is a long run of text.' | truncate_words: 3 }}
This is a...
upcase
Converts a string into uppercase.
{{ 'MIxed Case TExt' | upcase }}
MIXED CASE TEXT
url_escape
URI-escape a string, for inclusion in a URL.
{{ 'This & that//' | url_escape }}
This+%26+that%2F%2F
xml_escape
XML-escape a string, for inclusion in XML output.
{{ '<p>test</p>' | xml_escape }}
<p>test</p>