Template functions
Template functions:
- implement control flow and conditionals, for example
if()
andswitch()
- render widgets and snippets of HTML, for example
std:ui:notice()
andstd:form:token()
- include other templates in the current template.
There are three categories of template functions provided by the platform:
- language functions, which implement core features of the HSVT language
- ui functions, which affect the rendering of the standard Haplo UI
- platform functions, which provide rendering of widgets
Plugins can define their own template functions. These are made available to all plugins, so must be in an appropriate namespace.
Function syntax
A function is formed of
- the function name
- an open bracket
(
- zero or more arguments, separated by spaces (not commas)
- a close bracket
)
- an optional anonymous block
- zero or more named blocks
A block is a number of other language elements enclosed in {}
brackets, and a named block is prefixed by a name.
For example, the usual if()
function looks like
if(value) { "True" } else { "False" }
and is formed of the name, a single argument in ()
brackets, an anonymous block containing the literal "True"
and a named else
block containing the literal "False"
.
But of course, functions can be as simple as this
<form method="POST"> std:form:token() // ... </form>
where std:form:token()
includes the standard CSRF token into your view.