You can define a function like this:
<function functionName(argName1, argName2...)> Some HTML... </function>
A function can have zero or more arguments. The function name and argument names must be legal identifiers. You can call a function like this:
<call functionName(arg1, arg2...)>The arguments must be valid expressions. For example:
<function showLink(url, image, alt)> <a href="${url}"> <if preferences.showImages> <img src="${image}" border="0" alt="${alt}"> <else> ${alt} </if> </a> </function> ...some HTML... <call showLink(urls.home, images.home, "Home")> ...more HTML...
Functions are defined at compile time, so it's fine to call a function that's defined further down in the template. Make sure your function names don't conflict with your variable names; the template processor may get confused if they do. Note that functions, which are written in template language, are different from methods, which represent Java objects in the data model. Methods can only be called in expressions, and produce no output except for their return value. Functions cannot be used in expressions; the only way to call a function is by using the <call> tag.
Recursive function calls are supported.
Previous: Assignment | Next: Includes |