Template Module

The Template Module provides the tools and API to execute XWiki templates i.e. files or wiki pages used to display the general UI.

The Template Manager

The TemplateManager component is the main entry point of the module. A template is represented by the Template interface which provides the functions for accessing the TemplateContent and its path and ID.


1.Find the template having the ID "mytemplate.vm":

TemplateManager templateManager;

Template template = templateManager.getTemplate("mytemplate.vm");

2. Execute the template having the ID "mytemplate.vm":

TemplateManager templateManager;

String html = templateManager.render("mytemplate.vm");

3. Find and execute the template with ID "mytemplate.vm" and get a XDOM:

TemplateManager templateManager;

XDOM result = templateManager.execute("mytemplate.vm");

4. Find and parse the template with ID "mytemplate.vm" without executing it:

TemplateManager templateManager;

XDOM xdom = templateManager.getXDOM("mytemplate.vm");

Templates Reference

  • Template Macro - allows to include the script passed as argument into the current script. Note that only the Velocity parser will be executed on the file passed as argument.
  • Override wiki templates using the Skin Application linked under "Related Pages".

Usage from Velocity

The Template Module API is exposed in Velocity using a script service: $services.template.*



Control the Template Behavior

Wiki templates are usually Velocity scripts that produce HTML content. In order to control their behavior, you can use the following properties:

Property NameValuesDescription
source.syntaxrendering input syntaxThe identifier of the parser to use in order to interpret the content of the template.
raw.syntaxrendering input syntaxWhen source.syntax is not set, it is the syntax that will be put in the RawBlock produced with the result of the Velocity execution.
authorA reference to an XWiki userThe user to use as author of the template content when executing it. It is only taken into account for file system templates - wiki based templates will use their actual author.
privilegedtrue or falseForce the file system template to have Programming Rights. In practice, it means its author will be "xwiki:XWiki.superadmin".


Search this space