String filters manipulate strings.

append

Appends a string to the end of another string.

Code
{{ 'filename' | append: '.js' }}
Output
filename.js

capitalize

capitalizes the first word in a string.

Code
{{ 'capitalize me' | capitalize }}
Output
Capitalize Me

downcase

Converts a string into lowercase.

Code
{{ 'MIxed Case TExt' | downcase }}
Output
mixed case text

escape

HTML-escapes a string.

Code
{{ '<p>test</p>' | escape }}
Output
&lt;p&gt;test&lt;/p&gt;

newline_to_br

Inserts a <br /> linebreak HTML tag at each line break in a string.

Code
{% capture text %}
A
B
C
{% endcapture %}
{{ text | newline_to_br }}
Output
A<br />
B<br />
C<br />

prepend

Prepends a string to the beginning of another string.

Code
{{ 'Jane Johnson' | prepend: 'Dr. ' }}
Output
Dr. Jane Johnson

remove

Remove all occurrences of a substring from a string.

Code
{{ 'Hello, Dave. How are you, Dave?' | remove: 'Dave' }}
Output
Hello, . How are you, ?

remove_first

Removes the first occurrence of a substring from a string.

Code
{{ 'Hello, Dave. How are you, Dave?' | remove_first: 'Dave' }}
Output
Hello, . How are you, Dave?

replace

Replaces all occurrences of a string with a substring.

Code
{{ 'Hello, Dave. How are you, Dave?' | replace: 'Dave', 'John' }}
Output
Hello, John. How are you, John?

replace_first

Replaces the first occurrence of a string with a substring.

Code
{{ 'Hello, Dave. How are you, Dave?' | replace_first: 'Dave', 'John' }}
Output
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.

Code
{% 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: ', ' }}
Output

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.

Code
<p>Hello</p>
Output
Hello

strip_newlines

Strips any line breaks from a string.

Code
{% capture text %}
A
B
C
{% endcapture %}
{{ text | strip_newlines }}
Output
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.

Code
{{ note.notetext | text_to_html }}
Output
<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.

Code
{{ 'This is a long run of text.' | truncate: 10 }}
Output
This is...

truncate_words

Truncates a string down to a given number of words. An ellipsis (...) is appended to the truncated string.

Code
{{ 'This is a long run of text.' | truncate_words: 3 }}
Output
This is a...

upcase

Converts a string into uppercase.

Code
{{ 'MIxed Case TExt' | upcase }}
Output
MIXED CASE TEXT

url_escape

URI-escape a string, for inclusion in a URL.

Code
{{ 'This & that//' | url_escape }}
Output
This+%26+that%2F%2F

xml_escape

XML-escape a string, for inclusion in XML output.

Code
{{ '<p>test</p>' | xml_escape }}
Output
&lt;p&gt;test&lt;/p&gt;