Change theme:   

Filters

Output markup can be passed through filters. Filters are simple methods, the first parameter is always the output of the left side of the filter. The return value of the filter will be the new left value when the next filter is run. When there are no more filters the template will receive the resulting string.

Filters can be applied to variable output, for example, to make "test" uppercased, "upcase" filter can be used: {{ ‘test’ | upcase }}

{{ 'test' | capitalize }}
Word "test" has {{ 'test' | length }} letters!

capitalize

Capitalizes words in input.

{{ 'howdy developers!' | capitalize }}
#=> Howdy Developers!

date

Reformat a date

This page was last updated at {{ page.updated_at | date : "%d.%m.%Y" }}
#=> This page was last updated at 09.10.2008

Available date format attributes:

  %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

downcase

Downcases words in input

{{ 'SCREAM!' | downcase }}
#=> scream!

escape

Escapes HTML from output:

{{ "<b>I'm a big orangutang" | escape }}
#=> &lt;b&gt;I'm a big orangutang&lt;/b&gt;

first

Get the first element of passed in array

{{ blog.articles | first }}

format_date

Formats date in respect to active locale settings. For example if user is on page that is in french then day and monthnames will also be translated to french. Same formatting attributes apply as in date filter.

{{ page.updated_at | format_date:"%A, %d %B"}}
=> Vendredi, 5 Mars

This filter also accepts shortcut parameters to format date accordingly to locale settings. Format for date will be chosen by language that the current page is in. Valid shortcut arguments are default, long and short. Example:

{{ page.updated_at | format_date:"long" }}

h

Alias for escape.

join

Join elements of array with certain characters between them

last

Get the last element of passed in array

{{ blog.articles | last }}

size

Returns the length of an array or string

There are {{ blog.articles | size }} articles in this blog
#=> There are 5 articles in this blog

sort

Sort the elements of the array

strip_html

Removes HTML-tags from passed in string

{{ "<b>Do not cross the <a href="#yellow">yellow</a> line</b>" | strip_html }}
#=> Do not cross the yellow line

truncate

Truncate string down to predefined number of characters.

{{ "Quick brown fox jumps over the lazy dog" | truncate : 5 }}
#=> Quick...

Truncate string can also be defined:

{{ "Quick brown fox jumps over the lazy dog" | truncate : 5 : "--" }}
#=> Quick--

upcase

Converts all characters in string into upper-case

{{ "scream!" | upcase }}
#=> "SCREAM!"