getParent() does not point to logical Parent

I have simillar problem as here getParentReference does not point to logical Parent but internally in xwiki. I have a template provider which creates nested pages. My simple code:

{{velocity}}
#set($parent = $doc.getParent())
$parent
{{/velocity}}

produce output:

Templates.NewTemplateTest.WebHome

The problem is that the subpage should point to its new parent, but instead, it points to the original parent in the templates folder.

Im working on 16.1.0.

getParent() is very rarely what you want to use nowadays (we should probably discuss making it more explicitly deprecated, XWikiDocument#getParent already is deprecated)

The hierarchy of the page/document is all in its reference:

  • $doc.pageReference give you the reference of the current page (with page reference syntax, so / separator instead of . and no WebHome thingy)
  • $doc.pageReference.parent will give you the reference of its parent page
  • etc.

You have the same thing with $doc.documentReference, $doc.documentReference.parent, etc. but page references usually makes things a bit easier to understand since they match better how things are presented in the UI.

But until recently, getParent was correctly returning the parent created by the template. At some point (I can’t pinpoint exactly what changed), the child page started pointing back to the template. For pages created in the past, even now, when I edit them and add getParent, it correctly points to the parent. So, how can I achieve the same effect with pageReference?

And how can I get the children of the parent obtained in this way? I want to have links on the subpage that refer to other subpages, so I need to retrieve the other children of the parent.

And how to use documentTree macro for parent in this way?

I did not say it’s always different from the real parent, just that it’s not necessarily accurate, since the fact that it can point anywhere is a feature (it’s just not displayed anymore in the UI by default).

I’m not sure which “effect” you are referring to, pageReference.parent is always the parent of the page in the real hierarchy (where the page is actually stored and what the breadcrumbs show you), you cannot customize it like the legacy metadata called “parent”.

If you just want the siblings of your page, the easiest would probably be to use a query to search all the documents located in the same space as your parent (so $doc.space for example) as your document.

I don’t know the documentTree macro very well, but https://extensions.xwiki.org/xwiki/bin/view/Extension/Document+Tree+Macro#HChildrenPages seems to be what you are asking for.

@XwikiEnjoyer Hello. Maybe check this page to understand the history and the difference between the old Parent concept and the newer nested page reference one: https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/ContentOrganization/NestedPagesMigration/#HParent2FChildrelationship

Hope it helps

Ok, but the problem is that without any changes, my macro in the panels that used getParent() stopped working. Previously, it correctly pointed to its parent after being created from the template, but now it refers to the parent as Templates.XXX.WebHome. What could have happened? How, then, can I get the other siblings from the perspective of a child created from a template?

Are you sure you didn’t do any change, like upgrade XWiki?

What could have changes is that Panels can “now” be asynchronous (see https://extensions.xwiki.org/xwiki/bin/view/Extension/Panels%20Application#H22Asynchronousrendering22), and when that’s the case, the current reference could be different depending on whether you defined the current request/reference or not in the context elements.

What does “previously” mean?

Thx