Print
Template Registry

Multiple named templates can be placed in a simple file and loaded into a template registry, for easy use. The code snippet below shows two named templates notice the ::=<< and >>=:: delimiters to identify the start and end of each named template.

someTemplateName() ::=<<
...template goes here...
>>=::&nbsp;

someOtherTemplateName() ::=<<
...template goes here...
>>=::

A Template registry is created and the templated loaded using the registerTemplate method.

TemplateRegistry registry&nbsp;&nbsp; = new MVELTemplateRegistry();
registry.registerTemplate( new InputStreamReader( MyClasss.class.getResourceAsStream( "my_templates.mvel" ) ) );

A template from the reigstry can then be parsed using the TemplateInterpreter.parse method.

TemplateInterpreter.parse( registry.getTemplate( "someTemplateName"),
                           null,
                           vars,
                           registry )
Powered by Atlassian Confluence