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)
ceil(decimal) Returns the largest integer from a decimal number. ceil(4.2) 5
cos(number) Returns the cosine of the number. cos(0) 1
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


get(variable) Returns a variable set earlier using the set() function. get('foo') bar
hexstr(integer) Returns a hexadecimal string from an integer or hex value. hexstr(13)
hexstr(0xF - c)
hexstr2(integer) Same as hexstr(), but pre-pads with a zero on single digit. This is perfect for creating hex triplets in calculated colors, since RGB is 3 sets of hex values. hexstr2(255)
hexstr2(0xFF - 10)
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
sin(number) Returns the sine of the number. sin(0) 0
sqrt(number) Returns the square root of the number. sqrt(4) 2
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