Document self-reference for documentTree in Templates


I’m trying to create a template that features a page tree macro to display the documents below any page created from the template.
Unfortunately, the children macro is not sufficient here as it does not allow to specify an equivalent to the openTo parameter and also does not allow for the removal of attachments and translations.

I have tried adding the following to the page source:

{{documentTree showTranslations="false" showAttachments="false" root="$doc.documentReference" openTo="$doc.documentReference"/}}

But that only resulted in

 Left side ($childNodeIds.size()) of comparison operation has null value at ost:XWiki.DocumentTree[line 153, column 29]

Is there any way to achieve what I want?


You need to read the documentation for the root and openTo parameters. See .

Well, I did :wink:
And yes. It works with the explicit node ID.
However, I want to add this documentTree macro to a template, so imho need some sort of a placeholder that is replaced by the node ID of the document that is created from this template.

So are you saying that, if I use the node ID of the template itself in the template, this will be replaced when I create a new page from it?
Or is this not possible at all and I have to manage the root and openTo of that macro for every page I create from that template individually?

Well, there is this part:

The format of a node identifier is entityType:entityReference, where the entity type can be for instance wiki, space, document. E.g.: wiki:xwiki, space:xwiki:Main, document:xwiki:Main.WebHome.

$doc.documentReference that you’re using as value for the root and openTo parameters is not the node id. It’s just the document reference. The node id must include also the entity type (e.g. document:), because the entity reference alone is not enough: you need to know the entity type in order to parse the entity reference. And the document tree has nodes that correspond to different entity types, so it needs to determine the node type from the node id. Which is not possible if you pass only the document reference.

Looking at the Entity Reference API docs, that seemed implicit to me, given that the attribute is called documentReference as opposed to e.g. spaceReference.

Thanks a lot though, works when providing the entity type.