Templates
Explanation
The Template Module executes the files and wiki pages that render the XWiki user interface around the content of the page being viewed. Such a file is called a template, it is written in Velocity, and it is named by its file name, as in mytemplate.vm.
Where XWiki looks for a template
org.xwiki.template.TemplateManager resolves a template name against three sources and stops at the first one that answers:
- Skin templates are resources of the current skin or of one of its parent skins. A skin can be a wiki page, which is how an administrator replaces a template without touching the filesystem, as described in Customize Skin.
- Filesystem templates are files in the templates/ folder of the WAR, or in a filesystem skin under skins/.
- Classloader templates are resources in the templates package of a JAR, or in WEB-INF/classes/templates in the WAR.
Rights and caching
Filesystem and classloader templates have programming right by default: they are executed as xwiki:XWiki.superadmin, which the privileged property turns off. A wiki template is always executed with the right of its own author, so neither privileged nor author has any effect on it.
Wiki and filesystem templates are cached, and an entry is dropped when the template is modified. Velocity also compiles each template once and caches the compiled form. A request carrying the following header skips the template cache, which is what a browser sends when the reader forces a refresh:
Cache-Control: no-cacheRunning a template
Execute a Template calls TemplateManager from a component. A wiki page runs the same template with the template macro, and a script with the template script service:
{{template name="mytemplate.vm"/}}
$services.template.render('mytemplate.vm')Write a Template adds one to a JAR or to the WAR, and Template Properties documents the header that controls how it is parsed and executed.
FAQ
Is this the same thing as a page template?
No. A page template is a wiki page copied when a user creates a page. A template here is a Velocity fragment that renders part of the user interface.
Where are the templates XWiki itself ships?
In the xwiki-platform-web-templates module, whose templates/ folder holds the .vm files rendering the standard user interface.
More
To find more about the current topic, you can search or use the table below and filter the columns to narrow your choices.