|
Functions Modifiers Functions
|
array
Call Prototype:
array
[ mixed ... ]
Return Value:
return → array
All of the parameters returned as an array. Description:
Returns all of the parameters converted into an array. Named parameters result in appropriate array keys, while unnamed parameters result in appropriate array indexes.
basename
Call Prototype:
basename
path=string
Parameters:
path
File path name.
Return Value:
return → string
Just the file portion of $path. Description:
Equivalent to PHP's basename().
checked
Call Prototype:
checked
test=mixed
Parameters:
test
The test expression.
Return Value:
return → string
The string ' checked="checked" ' if $test is true. Description:
If the given input is a true value, then the HTML attribute code checked="checked" is returned.
This is useful to use inside of HTML checkbox and radio input tags to determine if the element should be checked by default. e.g. <input type="checkbox" name="first" {% checked test=$first=='on' %}>
<input type="checkbox" name="second" {% checked test=$second=='on' %}> count
Call Prototype:
count
array=array
Parameters:
array
Array to count.
Return Value:
return → int
Number of elements in the array. Description:
Returns the number of elements within the given array, using the internal PHP count() function.
cycle
Call Prototype:
cycle
Return Value:
return → int
Alternates between returning 0 and 1. Description:
Returns either 0 or 1, each time returning the opposite of the value returned from the prior call. The first call will return 0, the second returns 1, and third returns 0, and so on.
This is most useful when printing rows of data that should be displayed in alternating colors use CSS. Example: <tr class="row{% cycle %}"> date
Call Prototype:
date
format=string
[
date=mixed
]
Parameters:
format
The format to use, from the PHP date() function. (default 'r')
date
The current date, either as a string or a timestamp.
Return Value:
return → string
The formatted date. Description:
Formats the input date, or the current date if no date is given.
default
Call Prototype:
default
value=mixed
default=mixed
Parameters:
value
The value to test and return if true.
default
The value to return if $value is false.
Return Value:
return → mixed
$value if it is true, otherwise $false. Description:
Tests the first value given and, if it is a true value, returns that value. If the value is false, the second value is returned instead.
The code {% default value=$value default=$default %} is equivalent to {% if $value ; $value ; else ; $default ; end %} This is particularly useful for the value attribute for form input tags when used in conjunction with a user-input value and the form's default value.
disabled
Call Prototype:
disabled
test=mixed
Parameters:
test
The test expression.
Return Value:
return → string
The string ' disabled="disabled" ' if $test is true. Description:
If the given input is a true value, then the HTML attribute code disabled="disabled" is returned.
This is useful to use inside of HTML input elements. e.g. <input type="checkbox" name="first" {% disabled test=$first=='on' %}>
<input type="checkbox" name="second" {% disabled test=$second=='on' %}> eval
Call Prototype:
eval
source=string
Parameters:
source
The template code to evaluate.
Return Value:
return → string
The output of the source after evaluation. Description:
Evaluate template code given as a string and reeturn the result.
include
Call Prototype:
include
tpl=string
Parameters:
tpl
The template path to include.
Description:
This function loads up a template file and displays it.
isset
Call Prototype:
isset
object=array|object
index=mixed
Parameters:
object
Array or object to look inside.
index
The index to look for.
Return Value:
return → bool
True if the index is found, false otherwise. Description:
Equivalent to PHP's isset() function.
join
Also Known As:
implode
Call Prototype:
join
separator=string
array=array
implode separator=string array=array Parameters:
separator
String to put between joined elements.
array
Array to join.
Return Value:
return → string
All elements of $array joined together. Description:
Joins all of the elements of the given array together into a single string, with each element separated by the given separator.
Equivalent to PHP's implode(). json
Call Prototype:
json
value=mixed
Parameters:
value
Value to encode.
Return Value:
return → string
Value encoded in JSON/JavaScript notation. Description:
Convers the input value into the proper code necessary to recreate the value in JSON notation. Useful for exporting template variables to JavaScript.
ldelim
Call Prototype:
ldelim
Return Value:
return → string
Left delimiter. Description:
Returns the left delimiter token.
merge
Call Prototype:
merge
[ array ... ]
Return Value:
return → array
All input arrays merged. Description:
Takes any number of arrays and merges them into a single array. Non-array values given are ignored.
Equivalent to PHP's array_merge(). nl2br
Call Prototype:
nl2br
string=string
Parameters:
string
The string to process.
Return Value:
return → raw
$string all newlines replaced with '<br />' and all HTML special characters escaped. Description:
Equivalent to calling Sugar::escape() followed by PHP's nl2br().
printf
Also Known As:
sprintf
Call Prototype:
printf
format=string
params=array
sprintf format=string params=array Parameters:
format
Format string.
params
Format parameters.
Return Value:
return → string
Formatted string. Description:
Formats the input arguments using sprintf().
psplit
Call Prototype:
psplit
expr=string
string=string
count=int
Parameters:
expr
Regular expression to split on.
string
String to split.
count
Maximum elements in result, or infinite if unset.
Description:
Splits the given input string into an array of elements using a regular expression as the delimiter.
Example: {% psplit expr='/\s+/' string=$string %} Equivalent to PHP's preg_split().
rdelim
Call Prototype:
rdelim
Return Value:
return → string
Right delimiter. Description:
Returns the right delimiter token.
select
Call Prototype:
select
value=mixed
default=mixed
[ mixed ... ]
Parameters:
value
The value to look for.
default
The value to return if $value is not found.
Description:
Given a list of named parameters, return the parameter with the name equal to the $value parameter. If no such parameter is found, return the $default parameter, or the value of $value itself if $default is not set.
Example: $n = 'foo'; select value=$n default='not found' foo='Found Foo' bar='Found Bar'
// would print 'Found Foo' selected
Call Prototype:
selected
test=mixed
Parameters:
test
The test expression.
Return Value:
return → string
The string ' selected="selected" ' if $test is true. Description:
If the given input is a true value, then the HTML attribute code selected="selected" is returned.
This is useful to use inside of HTML option tags to determine if the option should be selected by default. e.g. <option {% selected test=$value=='First' %}>First</option>
<option {% selected test=$value=='Second' %}>Second</option> <option {% selected test=$value=='Third' %}>Third</option> split
Also Known As:
explode
Call Prototype:
split
delimiter=string
string=string
count=int
explode delimiter=string string=string count=int Parameters:
delimiter
Separator to split on.
string
String to split.
count
Maximum elements in result, or infinite if unset.
Description:
Splits the given input string into an array of elements.
Equivalent to PHP's explode(). strtolower
Call Prototype:
strtolower
string=string
Parameters:
string
The string to process.
Return Value:
return → string
$string with all characters lower-cased. Description:
Equivalent to PHP's strtolower().
strtoupper
Call Prototype:
strtoupper
string=string
Parameters:
string
The string to process.
Return Value:
return → string
$string with all characters upper-cased. Description:
Equivalent to PHP's strtoupper().
substr
Call Prototype:
substr
string=string
start=int
length=int
Parameters:
string
The string to cut.
start
The position to cut at.
length
The number of characters to cut.
Return Value:
return → string
The cut string. Description:
Returns a portion of the input string, no more than $length characters long, starting the character index $index.
Examples: substr string='hello world' start=2 length=6 // llo wo
substr string='hello world' start=0 length=5 // hello substr string='hello world' start=6 length=5 // world substr string='hello world' start=10 length=5 // ld time
Call Prototype:
time
Return Value:
return → int
Current UNIX timestamp. Description:
Equivalent to PHP's time().
truncate
Call Prototype:
truncate
string=string
length=int
end=string
Parameters:
string
The string to truncade.
length
The maximum length. (default 72)
end
String to append after truncation. (default '...')
Return Value:
return → string
The truncated string Description:
Truncates the input string to a maximum of $length characters. If the string requires truncation, the value of $end will be appended to the truncated string. The length of $end is taken into account to ensure that the result will never be more than $length characters.
urlencode
Call Prototype:
urlencode
[
string=string
]
[
array=array
]
Parameters:
string
A string to encode.
array
An array of key/value pairs.
Return Value:
return → string
URL-encoded string. Description:
Converts an input string into a URL-encoded string. If the input value is an array, the result is a URL-encoded string of each key/value pair separated by ampersands (&).
var
Call Prototype:
var
name=string
Parameters:
name
The variable to lookup.
Return Value:
return → mixed
The value of the requested variable. Description:
This returns the value of the requested variable. This function is useful when the name of a variable required is known only by the value of another variable.
In particular, these three lines are equivalent: {% $foo %}
{% var name='foo' %} {% $name = 'foo' ; var name=$name %} default
Call Prototype:
| default
: mixed
: mixed
Parameters:
mixed
Value to test.
mixed
Value to use if $value is unset.
Description:
If $value is not null, return $value, otherwise return $default.
Example: {% $undefined |default:'Not Defined' %}
escape
Call Prototype:
| escape
: mixed
: string
Parameters:
mixed
String (or any other type) to escape.
string
Escape format to use. (default 'html')
Description:
Mode must be one of 'html', 'xml', 'json', or 'url'.
The input value is escaped according to the rules of $mode, resulting in a raw string which can be safely printed out. For the mode 'json', this is equivalent to: {% json value=$value %} For the mode 'url', this is equivalent to: {% urlencode string=$value %} For the modes 'html' and 'xml', this is equivalent to the default output encoding rules for both languages.
int
Call Prototype:
| int
: mixed
Parameters:
mixed
Value to convert.
Description:
Converts the input value into an integer.
Equivalent to PHP's intval(). lower
Call Prototype:
| lower
: string
Parameters:
string
String to convert.
Description:
Converts a string to all lower case letters.
Equivalent to PHP's strtolower(). |