-
Notifications
You must be signed in to change notification settings - Fork 56
Built in filters
Here is a list of built-in filters in h2o.
convert variable to lower case.
{{ 'Upper CASE ' | lower }}
// outputs "upper case"
convert variable to upper case.
{{ 'lower case' | upper }}
// outputs "LOWER CASE"
Capitalize a value. The first character will be uppercase, all others lowercase.
{{ 'page title' | capitalize }}
// outputs "Page Title"
capitalize the first character of the string
remove leading and trailing spaces.
{{ ' example text ' | trim }}
// outputs "example text"
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”
returns string wrapped after 75 characters
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"
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.
alias to escapeMarks a string as not requiring further HTML escaping prior to output.
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: “…”)
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.
syntax: limitwords [limit = 50] [ending = “…”]
return only [limit] (default:50) number of words and append with a ellipsis[ending] (default: “…”)
syntax : linebreaks(format = “p”) parameter: format – “p” or “br” convert linebreaks in windows, macintosh and unix/linux (“?”) into [format] tag, convert newline toalias to linebreaks convert newline to
alias to linebreaks
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"
depreciated : use currency instead
syntax:
currency(currency = “USD”, decimal = ‘.’, parenthesis_for_negative = true)
format a numeric value to currency
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
/*
$lucky_numbers = array( 12, 25, 33, 45);
*/
{{ lucky_numbers | first }}
//outputs 12
/*
$lucky_numbers = array( 12, 25, 33, 45);
*/
{{ lucky_numbers | last }}
//outputs 45
syntax: join( delimiter = ", ")
join a array/list variable with [delimitor]
/*
$sports = array('swimming', 'football', 'running');
*/
{{ sports | join }}
//outputs "swimming, football, running"
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”
{{ "blog post : Search Engine Optimist offers free service !" | hyphenize }}
// outputs "blog-post-search-engine-optimist-offers-free-service"
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>"