Skip to content
This repository

Filter reference

Here is a list of built-in filters in h2o.

lower

convert variable to lower case.


{{ 'Upper CASE ' | lower }}
// outputs "upper case"

upper

convert variable to upper case.


{{ 'lower case' | upper }}
// outputs "LOWER CASE"

capitalize

Capitalize a value. The first character will be uppercase, all others lowercase.


{{ 'page title' | capitalize }}
// outputs "Page Title"

capfirst

capitalize the first character of the string

trim

remove leading and trailing spaces.


{{ '  example text  ' | trim }}
// outputs "example text"

length

the number of item in a collection or the length of a string.

String


{{ 'good morning' | length }}
//outputs "12"

Object or Array
(list of page comments)


/*
 $page = array('comments'=> array('good thinking', 'i can do better'));
*/

{{ page.comments | length }}
// outputs “2”

wordwrap

returns string wrapped after 75 characters

default

set default value if variable is undefined


// let's say we haven't define $page['description'] yet
{{ page.description | default "page has no description" }}

// outputs "page has no description"

escape

syntax: escape [boolean]
Convert special characters to HTML entities.

if second parameter is set true, it will also convert single and double quotes ("), (’) to HTML entities.

e

alias to escape

safe

Marks a string as not requiring further HTML escaping prior to output.

truncate

return the truncated version of the string, first parameter will be the length (default:50), second parameter is string to be append at the end other than ellipsis ( default: “…”)

strip_tags

remove all html or markup tags such as script, style, comments and return the readable text content. PHP’s strip_tags is only doing half.

limitwords

syntax: limitwords [limit = 50] [ending = “…”]

return only [limit] (default:50) number of words and append with a ellipsis[ending] (default: “…”)

linebreaks

syntax : linebreaks(format = “p”) parameter: format – “p” or “br” convert linebreaks in windows, macintosh and unix/linux (“?”) into [format] tag,

nl2br

convert newline to
alias to linebreaks

nl2pbr

convert newline to

alias to linebreaks

numberformat

syntax:
numberformat [decimals], [decimal_point_string], [thausands_seperator]

alias to PHP number_format() function.
( float $number [, int $decimals [, string $dec_point, string $thousands_sep]] )


{{ 125 | numberformat 3 }}
// ouputs "125.000"

moneyformat

depreciated : use currency instead

currency

syntax:
currency(currency = “USD”, decimal = ‘.’, parenthesis_for_negative = true)

format a numeric value to currency

date

syntax: date(format=“Y M d”)

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.
where format is the same as PHP date() function http://www.php.net/date

relative_date

if timestamp is within 7 days. this will format timestamp to relative date in words, eg: today, yesterday, 2 days ago. otherwise this will return to [#date]

relative_time

syntax: relative_time if timstamp is today, this will format timestamp to relative time in words. eg: 10 minutes ago, 5 hours ago otherwise this will return to [#date]

relative_datetime

if timestamp is today return [#relative_time] if timestamp is within 7 days return [#relative_date] otherwise return [#date]

filesize

filesize will format numeric number of bytes into “human-readable” file size (eg: KB, MB, GB, TB … )

first

return the first element of a array/list/dictionary

 /*
   $lucky_numbers = array( 12, 25, 33, 45);
 */
 {{ lucky_numbers | first }}

 //outputs 12

last

return the last element of a array/list/dictionary

 /*
   $lucky_numbers = array( 12, 25, 33, 45);
 */
 {{ lucky_numbers | last }}

 //outputs 45

join

syntax: join( delimiter = ", ")

join a array/list variable with [delimitor]


/*
 $sports = array('swimming', 'football', 'running'); 
*/
{{ sports | join }}

//outputs "swimming, football, running"

urlencode

encode string or associative array into url friendly string or query string.

String


   {{ 'peter chan' | urlencode }}
   //outputs "peter%20chan"

Associative array or Dictionary


/*
   $search_params = array('name'=>'peter chan', 'mode'=>'person_search');
*/

{{ search_params | urlencode }}
// outputs “name=peter%20chan&mode=person_search”

hyphenize

format string into URL and SEO friendly URLS, convert white space and non-alphanumeric character into hyphen, all lower cased

 {{ "blog post : Search Engine Optimist offers free service !" | hyphenize }}
 // outputs "blog-post-search-engine-optimist-offers-free-service"

urlize

syntax: urlize(truncate = false)

parameter:
truncate – optional interger to truncate the link
Converts URLs in plain text into clickable links.


{{ "http://www.yahoo.com" | urlize }}
// outputs "<a href='http://www.yahoo.com'>http://www.yahoo.com</a>"

{{ "http://www.google.com/webmaster/guidline.html" | urlize 30 }}
// outputs "<a href='http://www.google.com/webmaster/guidline.html'>http://www.google.com/webmaste...</a>"

links_to

{{ "homepage"|links_to 'http://google.com' }}

Something went wrong with that request. Please try again.