Skip to content

Nested Templates

tporcham edited this page Jan 30, 2019 · 1 revision

Using the Template Registry you can nest templates inside each other and call them like methods. To call a template inside another template use the 'includeByRef' tag. You must pass any variables used by the nested template via key/value parameters, as shown by the user template parameter in the following example. The following example parses a template which does nothing other than include another template. Recursion is allowed.

TemplateRegistry registry = new MVELTemplateRegistry();
registry.registerTemplate("welcomeUser", "Hellow @{user}");
TemplateInterpreter.parse("@includeByRef{helloUser(user = \"bob\")}", base, map, registry);