Filters

Filters are simple methods that modify the output of numbers, strings, variables and objects in REACH. They are placed within an output tag {{ }} and are separated with a pipe character |.

Array

first – get the first element of the passed in array
last – get the last element of the passed in array
join – join elements of the array with certain character between them
map – map/collect an array on a given property
size – return the size of an array or string
sort – sort elements of the array
reversed – reverse the order of the elements in the array

Date

date – reformat a timestamp into another date format using strftime e.g. {{ “2014-12-25” | date: “%m/%d/%Y” }} #=> “12/25/2015”

Money

currency – convert an input string to currency e.g. {{ 50.0 | currency }} #=> $50.00
money_without_currency – convert an input string to currency without currency symbol e.g. {{ 50.0 | money_without_currency }} #=> 50.00
money_without_trailing_zeros – convert an input string to currency without trailing zeros e.g. {{ 50.0 | money_without_trailing_zeros }} #=> $50

QR Codes

qr_code – generate and insert a QR code with selected size 1 through 10 e.g. {{ sponsorship | qr_code: ‘2’ }}

String

append – append a string e.g. {{ ‘foo’ | append:’bar’ }} #=> ‘foobar’
capitalize – capitalize words in the input sentence
downcase – convert an input string to lowercase
escape – escape a string
escape_once – returns an escaped version of html without affecting existing escaped entities
newline_to_br – replace each newline (\n) with html break
phone – convert an input string to a phone number with the format (555) 555-5555
prepend – prepend a string e.g. {{ ‘bar’ | prepend:’foo’ }} #=> ‘foobar’
remove – remove each occurrence e.g. {{ ‘foobarfoobar’ | remove:’foo’ }} #=> ‘barbar’
remove_first – remove the first occurrence e.g. {{ ‘barbar’ | remove_first:’bar’ }} #=> ‘bar’
replace – replace each occurrence e.g. {{ ‘foofoo’ | replace:’foo’,’bar’ }} #=> ‘barbar’
replace_first – replace the first occurrence e.g. {{ ‘barbar’ | replace_first:’bar’,’foo’ }} #=> ‘foobar’
size – return the size of an array or string
strip_html – strip html from string
strip_newlines – strip all newlines (\n) from string
truncate – truncate a string down to x characters
truncatewords – truncate a string down to x words
upcase – convert an input string to uppercase

Math

divided_by – division e.g {{ 10 | divided_by:2 }} #=> 5
minus – subtraction e.g {{ 4 | minus:2 }} #=> 2
modulo – divide by a number and return the remainder e.g. {{ 14 | modulo:3 }} #=> 2
plus – addition e.g {{ ‘1’ | plus:’1′ }} #=> ’11’, {{ 1 | plus:1 }} #=> 2
round – round to integer or specified number of decimals e.g. {{ 3.14159 | round:2 }} #=> 3.14
times – multiplication e.g {{ ‘foo’ | times:4 }} #=> ‘foofoofoofoo’, {{ 5 | times:4 }} #=> 20

Tags: ,

Was this article helpful?

Previous Article

Tags Information

Next Article

Operators