|
Reusing Code with Template FunctionsYou 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 Recursive function calls are supported. Since FreeMarker 2.0rc3, you can use the |
|