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".


Related Pages

Search this space


Most popular tags

Failed to execute the [groovy] macro
  1. access rights
  2. activity stream
  3. annotation
  4. attachment
  5. comment
  6. Document Tree Macro
  7. export
  8. Extension Manager
  9. Flamingo skin
  10. global user
  11. Groovy event listener
  12. group
  13. nested page
  14. search
  15. skin
  16. syntax
  17. user
  18. user profile
  19. velocity macros
  20. wiki
  21. wysiwyg
  22. XWiki Applications
  23. xwikiattachment_archive table
  24. xwikiattachment table
  25. xwikiattrecyclebin table
  26. xwikiproperties table

[Display all tags from this space]