Page Templates API
Last modified by Pierre Jeanjean on 2026/11/24 14:20
Reference
XWiki 18.10.0+
The org.xwiki.platform:xwiki-platform-pagetemplate-api module reads template providers, from Java and from scripts. Its API is unstable.
Java
The org.xwiki.pagetemplate.TemplateProviderManager component role:
| Method | Returns |
|---|---|
| Optional<TemplateProvider> getTemplateProvider(DocumentReference reference) | The template provider defined in that Page, or an empty Optional when the Page holds no XWiki.TemplateProviderClass Object. Throws TemplateProviderException when the Page cannot be loaded. |
| List<TemplateProvider> getTemplateProviders() | The template providers of the current wiki, ordered by the full name of their Page, without checking the rights of the current user. XWiki.TemplateProviderTemplate, which new template providers are created from, is left out, and so is a template provider that cannot be loaded. Throws TemplateProviderException when they cannot be listed. |
@Inject
private TemplateProviderManager templateProviderManager;
public Optional<DocumentReference> getTemplate(DocumentReference providerReference) throws TemplateProviderException
{
return this.templateProviderManager.getTemplateProvider(providerReference)
.flatMap(TemplateProvider::getTemplateReference);
}Template Provider
A org.xwiki.pagetemplate.TemplateProvider holds the values of the template provider fields:
| Getter | Returns | Object property |
|---|---|---|
| DocumentReference getReference() | The reference of the Page holding the template provider | N/A |
| String getName() | The name, as plain text or a translation key, or null | name |
| String getDescription() | The description, as plain text or a translation key, or null | description |
| String getIcon() | The name of the icon, or null | icon |
| Optional<DocumentReference> getTemplateReference() | The reference of the template, or an empty Optional | template |
| String getAction() | edit, saveandedit or saveandview, or null | action |
| boolean isTerminal() | Whether the created Pages are terminal | terminal |
| List<SpaceReference> getVisibilityRestrictions() | The spaces the template provider is offered in, empty when offered everywhere | visibilityRestrictions |
| List<SpaceReference> getCreationRestrictions() | The spaces Pages can be created in, empty when they can be created anywhere | creationRestrictions |
| boolean areCreationRestrictionsSuggestions() | Whether the creation restrictions are only suggestions | creationRestrictionsAreSuggestions |
Script Service
$services.templateProvider.getTemplateProviders() returns the same list as its Java counterpart, keeping only the template providers the current user can view. When they cannot be listed, it logs a warning and returns an empty list.
{{velocity}}
#foreach ($provider in $services.templateProvider.getTemplateProviders())
#if ("$!provider.name" != '')
#set ($name = $services.localization.render($provider.name))
#else
#set ($name = $xwiki.getDocument($provider.reference).plainTitle)
#end
* $services.rendering.escape($name, 'xwiki/2.1')
#end
{{/velocity}}