Wiki source code of Navigation Tree API

Last modified by Pierre Jeanjean on 2026/02/05 17:22

Show last authors
1 A ##NavigationTreeSource## is a component that offers two methods:
2
3 {{code language="typescript"}}
4 import type { DocumentReference } from '@xwiki/platform-model-api';
5
6 /**
7 * Returns the direct child nodes for a given page id in the navigation tree.
8 * If the page id is omitted, returns the root nodes instead.
9 *
10 * @param id - the page id
11 * @returns the descendants in the navigation tree
12 */
13 getChildNodes(id?: string): Promise<Array<NavigationTreeNode>>;
14
15 /**
16 * Returns the ids of the parents nodes for a given page.
17 *
18 * @param page - the reference to the page
19 * @param includeTerminal - whether to include the final terminal page (default: true)
20 * @param includeRootNode - whether to include a root node with empty id (default: false)
21 * @returns the parents nodes ids
22 * @since 18.0.0RC1
23 * @beta
24 **/
25 getParentNodesId(
26 page: DocumentReference,
27 includeTerminal?: boolean,
28 includeRootNode?: boolean,
29 ): Array<string>;
30 {{/code}}
31
32 A ##NavigationTreeNode## is a simple data structure that stores all the information required render a node and to navigate the tree:
33
34 {{code language="typescript"}}
35 import type { SpaceReference } from '@xwiki/platform-model-api';
36
37 /**
38 * Description of a navigation tree node.
39 * @since 18.0.0RC1
40 * @beta
41 */
42 type NavigationTreeNode = {
43 /** the id of a node, used by the NavigationTreeSource to access children */
44 id: string;
45 label: string;
46 /**
47 * The location of the corresponding page on Cristal.
48 * @since 18.0.0RC1
49 * @beta
50 */
51 location: SpaceReference;
52 url: string;
53 has_children: boolean;
54 /**
55 * Whether this node corresponds to a terminal page.
56 * @since 18.0.0RC1
57 * @beta
58 */
59 is_terminal: boolean;
60 };
61 {{/code}}

Get Connected