Help
Frequently asked questions and other useful tidbits.
Text Filters
Updated on September 23rd, 2009
- size(string)
-
Returns the size of a string.
- downcase(string)
-
Converts a string to lower case.
- upcase(string)
-
Converts a string to upper case.
- capitalize(string)
-
Capitalizes words in a string.
- escape(string)
-
Removes special characters from a string. Useful for outputting attributes in HTML.
<a href="{{ product.url }}" title="View {{ product.name | escape }}">{{ product.name }}</a> - pluralize(string, count, singular, plural)
-
Returns the singular version of a word if there are one, and the plural version otherwise.
Options
You have {{ cart.item_count | pluralize: 'item', 'items' }} in your cart! - truncate(string, length, truncate_string)
-
Trims a string down to the length you specify.
Options
{{ product.name | truncate: 18 }} # => "Once upon a ti..." - truncatewords(string, length, truncate_string)
-
Trims a string down to the length you specify.
Options
{{ product.name | truncatewords: 4 }} # => "Once upon a time..." - strip_html(string)
-
Removes all HTML tags from a string.
- strip_newlines(string)
-
Removes all newlines (returns) from a string.
- newline_to_br(string)
-
Converts newlines (returns) into <br /> tags.
- paragraphs(string)
-
Converts newlines (returns) into <br /> tags and consecutive newlines into <p> tags.
- replace(string, string_to_find, replacement_string)
-
Replaces all occurrences of a string with another string.
{{ product.description | replace: "hello", "goodbye" }} - replace_first(string, string_to_find, replacement_string)
-
Same as replace, but only replaces the first occurrence.
- remove(string, string_to_remove)
-
Removes all occurrences of a given string.
- remove_first(string, string_to_remove)
-
Same as remove, but only removes the first occurrence.
- prepend(string, string_to_prepend)
-
Adds a string to the beginning of another string.
- append(string, string_to_append)
-
Adds a string to the end of another string.
- date(date, format)
-
Formats a date.
%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) %H - Hour of the day, 24-hour clock (00..23) %I - Hour of the day, 12-hour clock (01..12) %j - Day of the year (001..366) %m - Month of the year (01..12) %M - Minute of the hour (00..59) %p - Meridian indicator (``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
Contact
Can’t find an answer to your question? No worries, we’re here to help.