1

I'm building a custom panel for my Xwiki (Cloud hosted). I need to do a hierarchy tree on my panel, and for that, I need to know the parent of a space, so I can do an #if clause...

#set ($spaces = $xwiki.spaces)
#set ($hiddenSpaces = ["XWiki", "Admin", "Panels", "Blog", "Main"])
#foreach ($space in $spaces)

Here.. how can I achieve something like '$space.parent', that works on a doc????

Like I said I have tried with $space.parent, but this is not working.. it just prints it out on my screen...

Please, I'm stuck on this

EDIT: I think the objects returned by $xwiki.spaces are Strings... is there a way to get a space from the xwiki, something like $xwiki.getSpace($space).parent?

Gaston Claret
  • 1,000
  • 1
  • 7
  • 27

1 Answers1

2

There is no such thing as a the parent of a space yet, since XWiki only has documents represented in the database. However, by convention the space is usually represented by its homepage, SpaceName.WebHome. So, you should check the parent on this document.

#set ($spaces = $xwiki.spaces)
#set ($hiddenSpaces = ["XWiki", "Admin", "Panels", "Blog", "Main"])
#foreach ($space in $spaces)
  #set ($spaceHome = $xwiki.getDocument("${space}.WebHome"))
  #set ($spaceParent = $spaceHome.parent)
  ... and the rest of the code ...
#end

But this uses slightly deprecated methods. You should use entity references instead of strings:

  #set ($spaceHome = $xwiki.getDocument($services.model.createDocumentReference($doc.documentReference.wikiReference.name, $space, '', 'default')))
Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62
  • Thank you that helped me.. I'm almost there, now in my foreach, everything is getting obtained....how can i filter out the pages? I only need the spaces.. i think im missing a condition here? #set($query3="where doc.parent='$rdoc2'") – Gaston Claret Jul 19 '13 at 21:55
  • 1
    Again, there are only documents, while the spaces are virtual. You can't filter out documents from a query, since any (public) query returns just documents. You can do `where doc.parent='$rdoc2' and doc.name = 'WebHome'` to select only space homepages, or you can use the PR-protected `$xwiki.search("select doc.space from XWikiDocument doc where doc.parent = '$rdoc2'")`, but Programming Rights queries should only be used in extreme cases. – Sergiu Dumitriu Jul 20 '13 at 00:01