Built-ins
Built-ins provide certain functionality that is always available. Typically, a built-in provides a different version of a variable, or information about the variable in question. The syntax for accessing a built-in is the same as for accessing a sub-variable in a hash, except that you use the question mark instead of a dot. For example, to get the upper case version of a string: user?upper_case.
The following section lists the most commonly used built-ins. You can find a complete list of built-ins in Built-Ins Reference.
Built-ins to use with strings
Built-in Name |
Description |
html |
The string with all special HTML characters replaced by entity references (E.g. < with <) |
cap_first |
The string with the first letter converted to upper case |
lower_case |
The lowercase version of the string |
upper_case |
The uppercase version of the string |
trim |
The string without leading and trailing white spaces |
Built-ins to use with sequences
Built-in Name |
Description |
size |
The number of elements in the sequence |
Built-ins to use with numbers
Built-in Name |
Description |
int |
The integer part of a number (e.g. -1.9?int is -1) |
Example:
${test?html}
${test?upper_case?html}
Assuming that test stores the string “Tom & Jerry’'', the output will be:
Tom & Jerry
TOM & JERRY
Note the test?upper_case?html. Since the result of test?upper_case is a string, you can use the html built-in with it.
Another example:
${seasons?size}
${seasons[1]?cap_first} <#-- left side can by any expression -->
${"horse"?cap_first}
Assuming that seasons stores the sequence "winter", "spring", "summer", "autumn", the output will be:
4
Spring
Horse