"documentTree" Macro

Last modified by Lucas Charpentier on 2026/11/12 15:15

Reference

Description

The documentTree macro displays the pages of the wiki as a tree that the reader expands node by node. Depending on its parameters, the tree also shows wikis, spaces, attachments, translations, objects and class properties.

It is the tree of the Page Index. To list only the children of the current page, the "children" macro is a shorter way to write it.

Usage

{{documentTree/}}

In the WYSIWYG editor the macro is listed as "Page Tree", in the Navigation category. Its parameters are spread over four tabs: "Optional parameters", "Filters", "Elements to show" and "Display options".

The Edit Macro dialog of the Page Tree macro, on its first tab, with the Root field made of a node type button set to Document and a page reference

The macro is standalone only and takes no content. A tree with nothing to show displays the message "No pages found".

Node Identifiers

The root, openTo and exclusions parameters designate nodes of the tree. A node id is written type:reference. In the Edit Macro dialog, the "Root" and "Open to" fields are node pickers: a button selects the type and the field next to it takes the reference, with suggestions for pages and attachments.

Type in the PickerNode IdReference to Give
Farmfarm:*None: leave the field empty in the picker.
Wikiwiki:xwikiThe name of the wiki.
Spacespace:xwiki:SandboxThe reference of the space. For the page xwiki:Sandbox.WebHome it is xwiki:Sandbox.
Documentdocument:xwiki:Sandbox.WebHomeThe reference of the page. See how to get the reference of a page. document: alone is the current page.
All attachmentsattachments:xwiki:Sandbox.WebHomeThe reference of the page holding the attachments.
Attachmentattachment:xwiki:[email protected]The reference of the attachment.
All translationstranslations:xwiki:Sandbox.WebHomeThe reference of the translated page.
All objectsobjects:xwiki:Sandbox.WebHomeThe reference of the page holding the objects.
Objects of typeobjectsOfType:xwiki:Main.WebHome^XWiki.StyleSheetExtensionThe reference of the page, then ^ and the reference of the class. The picker offers no suggestion for this type.

A node is only reachable when the tree shows its type: a space: root needs showSpaces="true", an objects: root needs showObjects="true", and so on. Otherwise the tree displays "No pages found".

Velocity Macro

The same tree is available to scripts as the #documentTree Velocity macro of the documentTree_macros.vm template. It takes the same parameters as a map, except for exclusions, which expects a set of node ids instead of a comma-separated list.

{{template name="documentTree_macros.vm"/}}

{{velocity}}
{{html}}
#documentTree({'showAttachments': false, 'exclusions': $collectiontool.set})
{{/html}}
{{/velocity}}

Parameters

NameMandatoryAllowed ValuesDefault ValueDescription
rootnoa node idnoneThe node whose descendants are displayed. The root itself is not part of the tree unless showRoot is set. Without a root the tree displays the whole wiki.
openTonoa node idnoneThe node to open the tree to. All its ancestors, up to the root of the tree, are opened as well.
limitnoa positive integer15The maximum number of child nodes displayed when a node is expanded for the first time. The others are reached through a "more ..." link. When a single child is left over, it is displayed instead of the link.
sortDocumentsBynotitle, name, date for the last modification date or creationDate, optionally followed by :asc or :desctitle:asc when showDocumentTitle is true, name:asc otherwiseThe page field used to sort the child pages, and the sort order. The order is ascending when it is left out. The "Sort pages by" field of the Edit Macro dialog does not offer name: sorting on the page name is only available in wiki syntax. Sorting by title uses the raw title, so pages whose title is computed by a script may not be at the expected place.
readOnlynotrue, falsetrueSet it to false to let users who have the necessary rights change the tree structure, with drag and drop and a context menu on the nodes.
hierarchyModenoreference, parentchildreferenceThe hierarchy the tree follows. With reference, a page is under the page its reference is nested in. With parentchild, a page is under the page set as its parent, wherever it is located. This parameter is listed as advanced in the Edit Macro dialog.
exclusionsnoa comma-separated list of node idsnoneThe nodes to leave out of the tree, for instance exclusions="wiki:dev,document:xwiki:Sandbox.WebHome". It only applies when hierarchyMode is reference, and only to wiki and page nodes.
filterByClassnothe reference of a page holding a class, such as Blog.CategoryClassnoneShow only the pages that have an object of this class. It only applies when hierarchyMode is parentchild.
filterHiddenDocumentsnotrue, falsetrueWhen true, hidden pages are displayed or not according to the preference of the reader. Set it to false to always display them.
showAttachmentsnotrue, falsetrueWhether to show the attachments of each page, in an "Attachments" node.
showClassPropertiesnotrue, falsefalseWhether to show the class properties of the pages that define a class.
showDocumentTitlenotrue, falsetrueWhether a page node displays the title of the page, in the language of the reader, instead of its name.
showObjectsnotrue, falsefalseWhether to show the objects of each page.
showOnlyViewablenotrue, falsetrueShow only the wikis, spaces and pages the reader is allowed to view. When false, the others are listed by their name: the reader learns that they exist but still cannot open them.
showRootnotrue, falsefalseWhether to display the root node itself, above its children.
showSpacesnotrue, falsefalseWhether to show the space nodes. The pages are then grouped by space.
showTranslationsnotrue, falsetrueWhether to show the translations of each page, in a "Translations" node.
showWikiPrettyNamenotrue, falsetrueWhether a wiki node displays the pretty name of the wiki instead of its identifier.
showWikisnotrue, falsefalseWhether to show the wiki nodes. It only works on the main wiki, and when the page calling the macro was saved by a user with programming rights.
checkboxesnotrue, falsefalseWhether to display a checkbox in front of each node, to let the reader select several nodes.
compactnotrue, falsefalseHide the node icons and the lines connecting the nodes, so that the tree takes less horizontal space. Meant for narrow places such as a panel.
expandToLevelnoa positive integer or 00The number of levels opened when the tree is displayed. With 0 only the top level nodes are displayed, 1 opens them, 2 also opens their children, and so on. A high value makes the tree slow to display.
findernotrue, falsefalseWhether to display a search field above the tree. It suggests nodes as the reader types and opens the tree to the selected one.
linksnotrue, falsetrueWhether the node labels are links.

Examples

Display the Pages of the Wiki

{{documentTree/}}

Display the Pages Below a Page

The tree starts under the Team page and is opened one level deep. The Guides page has an attachment, hence its Attachments node.

{{documentTree root="document:xwiki:Sandbox.TreeShots.Team.WebHome" expandToLevel="1"/}}

A tree of three pages, Guides, Meetings and Release Notes, the first two opened on their child pages, and Guides also on an Attachments node

Display a Compact Tree of Pages Only

This is the form to use in a panel: no attachment, no translation, no icon.

{{documentTree root="document:xwiki:Sandbox.TreeShots.Team.WebHome" expandToLevel="1" showAttachments="false" showTranslations="false" compact="true"/}}

The same tree without icons, without connecting lines and without the Attachments node

Display the Root with Checkboxes and a Finder

{{documentTree root="document:xwiki:Sandbox.TreeShots.Team.WebHome" showRoot="true" checkboxes="true" finder="true"/}}

A search field above a tree that starts with the Team page, each node preceded by a checkbox

Group the Pages by Space

{{documentTree showSpaces="true"/}}

Follow the Parent of Each Page

The tree follows the parent set on each page instead of the page location. Add showSpaces="true" to also group the pages by space.

{{documentTree hierarchyMode="parentchild"/}}

Display Every Kind of Node

{{documentTree showWikis="true" showWikiPrettyName="false" showSpaces="true" showDocumentTitle="false" showObjects="true" showClassProperties="true"/}}

Related

Get Connected