PTPScript comes with a number of built-in functions, and these can easily be added to by the backend PHP programmer (or standard functions can be removed, or changed). A function is a PHP process rather than a PTPScript one. Although the same functionality can be achieved in some cases by using Macros, functions are quicker, and have far more power.

Functions are called by specifying the name of the function required, followed by parentheses. If necessary, parameters can be supplied within the parentheses, separated by commas. Each parameter can be any form of Expression, and the result of evaluating that expression will be passed to the function.

For example:

{ lowercase("Hello!") }
{ date("l dS \of F Y h:i:s", time()) }
{ round(22 / 7) }

Wednesday 24th of May 2006 08:44:29

Function names are case-insensitive.

Function calls are considered to be single terms in an expression, and so they can be used as such anywhere in an expression, in addition to containing further expressions as parameters.

PTPScript functions never modify their subject directly, but will instead return the modified subject where appropriate. For instance, using replace() on a String will return a copy of the String, in which the replacements have been made, rather than affecting the String directly.

Checking for functions

Sometimes it may be necessary to check for a function, and in such a situation, type checking should be used to determine whether the function is present.

For example:

{ if "lowercase" is a function }{   lowercase("Hello!") }
{ endif }
ptpscript/functions.txt · Last modified: 2007/01/24 10:15
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki