Text Filters

append

Append a string onto the end of another string.

Expects: String

Argument Required Description
string required The new string to append to the passed string
{{ 'foo' | append: 'bar' }} # => foobar

as_slug

Escape the given text to match the URL slugs Harmony generates.

Expects: String

{{ 'Blog Label Name' | as_slug }} # => blog-label-name

capitalize

Capitalize each word of a string.

Expects: String

{{ 'foo bar baz' | capitalize }} # => Foo Bar Baz

coderay

Syntax highlight code in your content. Wrap any code in <source:[lang]>… and Harmony will create markup for styling syntax.

Expects: text

{% assign text = "<source:ruby>class Foo\n  def bar\n    'baz'\n  end\nend</source>"

{{ text | coderay }}

To begin styling coderay syntax, create a new stylesheet in your theme, and select the ‘Coderay Syntax Highlighting’ preloaded CSS file.

Read more about Coderay to find out more info on Coderay, how to style the output, and available languages.

comment_count_text

Outputs the number of comments in correct human readable form.

Expects: Blog Post

{{ blog_post_1 | comment_count_text }} # => 6 Comments
{{ blog_post_2 | comment_count_text }} # => 1 Comment

date

Format a date into a string.

Expects: Date or String

Argument Required Description
string required The format string indicating how to display the date

Date will convert an existing date to a formatted string, or a string-based date (like ISO) and convert it to a date in the sites time zone, then format the date to the supplied format string.

{{ item.published_at | date: '%B %d, %Y %I:%M%p' }} # => December 25, 2009 8:47PM

To render the current date at time of render, as for the date of “now”.

{{ "now" | date: '%B %d, %Y %I:%M%p' }}

The following will be replaced in the format string with the appropriate data.

Code Description
%a The abbreviated weekday name (‘Sun’)
%A The full weekday name (‘Sunday’)
%b The abbreviated month name (‘Jan’)
%B The full month name (‘January’)
%c The preferred local date and time representation
%d Day of the month (01..31)
%-d Day of the month without leading zero (1..31)
%H Hour of the day, 24-hour clock (00..23)
%I (Uppercase i) Hour of the day, 12-hour clock, zero padded (01..12)
%l (Lowercase L) Hour of the day, 12-hour clock, no padding (1..12)
%j Day of the year (001..366)
%m Month of the year (01..12)
%-m Month of the year without leading zero (01..12)
%M Minute of the hour (00..59)
%p Meridian indicator (‘AM’ or ‘PM’)
%P Meridian indicator in lower case (‘am’ or ‘pm’)
%S Second of the minute (00..60)
%U Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
%W Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
%w Day of the week (Sunday is 0, 0..6)
%x Preferred representation for the date alone, no time
%X Preferred representation for the time alone, no date
%y Year without a century (00..99)
%Y Year with century
%Z Time zone name
%% Literal ‘%’ character

downcase

Turn the entire string to lowercase.

Expects: String

{{ 'FOO BAR' | downcase }} # => foo bar

escape

Escape any HTML entities to show properly in a browser as text.

Expects: String

{{ '<strong>' | escape }} # => &lt;strong&gt;

escape_url

Escape the given text to match the URL slugs Harmony generates.

Expects: String

{{ 'Blog Label Name' | escape_url }} # => blog-label-name

image_size_url

Takes an asset and provides the URL to a specific image size of that asset.

Expects: Asset

Argument Required Description
string required The slug of the desired image size.
{{ item.data.uploaded_file | image_size_url: 'large' }} # => /assets/89fdfs/large/filename.png

isodate

Output an ISO style date string for a given date.

Expects: Date

{{ item.created_at | isodate }} # => 2009-12-14T13:04:01-05:00

markdown

Run the given string through the markdown filter.

Expects: String

{{ "# Headline" | markdown }} # => <h1 id="headline">Headline</h1>

newline_to_br

Convert any newline characters in a string to
tags.

Expects: String

{{ "foo\nbar\nbaz" | newline_to_br }} # => foo<br />bar<br />baz

pluralize

Output a singular or plural string based on a given number.

Expects: Number

Argument Required Description
string required The singular version of the string.
string optional The plural version of the string. If none passed, it will use Harmony’s inflector to guess.
{{ item.data.number | pluralize: 'Widget' }} # => 8 Widgets

prepend

Prepend a string onto the front of another string.

Expects: String

Argument Required Description
string required The new string to prepend to the passed string
{{ 'foo' | prepend: 'bar' }} # => barfoo

replace

Replace each occurrence of a given string inside the passed string with another string.

Expects: String

Argument Required Description
string required The string to be replaced
string required The string to replace with
{{ 'foo bar foo' | replace: 'foo', 'baz' }} # => baz bar baz

replace_first

Replace only the first occurrence of a given string inside the passed string with another string.

Expects: String

Argument Required Description
string required The string to be replaced
string required The string to replace with
{{ 'foo bar foo' | replace_first: 'foo', 'baz' }} # => baz bar foo

remove

Remove every occurrence of a given string inside the passed string.

Expects: String

Argument Required Description
string required The string to be removed
{{ 'foobarfoo' | remove: 'foo' }} # => bar

remove_first

Remove only the first occurrence of a given string inside the passed string.

Expects: String

Argument Required Description
string required The string to be removed
{{ 'foobarfoo' | remove_first: 'foo' }} # => barfoo

size

Get the length of a string in characters.

Expects: String

{{ 'foobarbaz' | size }} # => 9

strip_html

Remove all HTML entities from a string.

Expects: String

{{ '<b>foobar</b>' | strip_html }} # => foobar

strip_newlines

Remove any newline characters in a string.

Expects: String

{{ "foo\nbar\nbaz" | strip_newlines }} # => foobarbaz

textilize

Run the given string through the textile filter.

Expects: String

{{ "*foobar*" | textilize }} # => <strong>foobar</strong>

truncate

Truncate a string down to a certain number of characters.

Expects: String

Argument Required Description
integer required The number of characters to leave in the string
{{ 'foobarbaz' | truncate: 5 }} # =>fooba

truncatewords

Truncate a string down to a certain number of words. If you are experiencing rendering issues and the text your truncating contains HTML, try using truncate_html instead.

Expects: String

Argument Required Description
integer required The number of words to leave in the string
{{ 'foo bar baz' | truncatewords: 2 }} # =>foo bar

truncate_html

Truncate a string containing HTML down to a certain number of words. This is different from truncatewords in that HTML tags are kept together and properly closed, whereas truncatewords can break HTML leading to rendering errors.

Expects: String

Argument Required Description
integer required The number of words to leave in the string
{{ '<a href="#">foo bar baz</a>' | truncate_html: 2 }} # => <a href="#">foo bar...</a>

Link usernames, lists, hash tags, and urls in text.

Expects: String

{{ '@orderedlist' | twitter_autolink }} # => @<a href="http://twitter.com/orderedlist" class="tweet-url username" rel="nofollow">orderedlist</a>

urldecode

Convert a URI encoded string so it is readable.

Expects: String

{{ 'Things+%26+stuff' | urldecode }} # => Things & stuff

urlencode

Convert a string so it can be used in a URI

Expects: String

{{ 'Things & stuff' | urlencode }} # => Things+%26+stuff

upcase

Turn the entire string to uppercase.

Expects: String

{{ 'foo bar' | upcase }} # => FOO BAR

widont

Insert a non-breaking space between the last two words of a string, to avoid widowed words.

Expects: String

{{ 'foo bar baz' | widont }} # => foo bar&nbsp;baz