Template Functions

There are a number of functions you can use inside the  template language. Functions must appear inside of braces.

{ ucfirst('jim') }

The following is a complete list of available functions.

Function Description Example Output
abs(number) Returns the absolute value of a number. abs(2)
abs(-2)
2
2
ceil(decimal) Returns the largest integer from a decimal number. ceil(4.2) 5
floor(decimal) Returns the smallest integer from a decimal number. floor(4.2) 4
format(pattern, var1) Formats a string according to a pattern.

%% - a percent sign
%s - a string of text
%d - an integer
%2d - an integer that uses 2 characters and pads with spaces
%02d - an integer that uses 2 characters and pads with zeros
%.1f - a floating point number with 1 digit after the decimal
%.2f - a floating point number with 2 digits after the decimal
format('Hello %s', $name)
format('%s %s', $color, $noun)    
format('%.2f', 7 / 3)
format('%.1f', 7 / 3)

format('%d', 7 / 3)
format('%2d', 7 / 3)
format('%02d', 7 / 3)


Hello Dave
red hand

2.33
2.3

2
 2
02
get(variable) Returns a variable set earlier using the set() function. get('foo') bar
lc(string) Lower cases a string. lc('aBcDeF') abcdef
plural(integer, format) Allows you to create pluralized text in an easy manner based upon what the value of the integer is.

There are some formatting symbols you should know:

%d - the quantity
() - optional, if plural
(||) - optional, inverted 
{|} - options

plural(0,'%d piece(s)')
plural(1,'%d piece(s)')
plural(2,'%d piece(s)')

plural(0,'action(s) need{|s|} to be taken')
plural(1,'action(s) need{|s|} to be taken')
plural(2,'action(s) need{|s|} to be taken')

plural(0,'{No|%d} cand(y|ies) (is|are) eaten')
plural(1,'{No|%d} cand(y|ies) (is|are) eaten')
plural(2,'{No|%d} cand(y|ies) (is|are) eaten')

plural(0,'{No|One|Two|Three|%d} item(s)')
plural(1,'{No|One|Two|Three|%d} item(s)')
plural(2,'{No|One|Two|Three|%d} item(s)')
plural(4,'{No|One|Two|Three|%d} item(s)')
0 pieces
1 piece
2 pieces

actions need to be taken
action needs to be taken
actions need to be taken

No candies are eaten
1 candy is eaten
2 candies are eaten

No items

One item

Two items

4 items
round(decimal) Returns the smallest integer from a decimal number if the remainder is less than 5 or the highest when it's 5 or above. round(4.2) 4
set(variable, value) Set a variable for retrieval later. set('foo','bar')
setget(variable, value) Set a variable for retrieval later, but also output it now. setget('foo','bar') bar
uc(string) Upper cases a string. uc('aBcDeF') ABCDEF
ucfirst(string) Upper cases the first letter in a string. ucfirst('aBcDeF') ABcDeF

Still need help? Contact Us Contact Us