1

我正在为我的 Xwiki(云托管)构建一个自定义面板。我需要在我的面板上做一个层次结构树,为此,我需要知道一个空间的父级,所以我可以做一个#if 子句......

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

在这里..我怎样才能实现像'$space.parent'这样的东西,它适用于文档????

就像我说的我已经尝试过使用 $space.parent,但这不起作用.. 它只是在我的屏幕上打印出来......

拜托,我坚持这个

编辑:我认为 $xwiki.spaces 返回的对象是字符串...有没有办法从 xwiki 获取空间,例如 $xwiki.getSpace($space).parent?

4

1 回答 1

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')))
于 2013-07-19T20:32:33.087 回答