【问题标题】:Know the parent of a space了解空间的父级
【发布时间】:2013-07-19 04:59:26
【问题描述】:

我正在为我的 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?

【问题讨论】:

    标签: wiki velocity xwiki


    【解决方案1】:

    目前还没有 空间的父级,因为 XWiki 只有在数据库中表示的文档。然而,按照惯例,该空间通常由它的主页表示,SpaceName.WebHome。因此,您应该检查此文档上的父级。

    #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
    

    但这使用了稍微不推荐使用的方法。您应该使用实体引用而不是字符串:

      #set ($spaceHome = $xwiki.getDocument($services.model.createDocumentReference($doc.documentReference.wikiReference.name, $space, '', 'default')))
    

    【讨论】:

    • 感谢您对我的帮助.. 我快到了,现在在我的 foreach 中,所有内容都已获取....如何过滤掉页面?我只需要空格..我想我在这里错过了一个条件? #set($query3="where doc.parent='$rdoc2'")
    • 再一次,只有文档,而空间是虚拟的。您不能从查询中过滤掉文档,因为任何(公共)查询都只返回文档。您可以使用where doc.parent='$rdoc2' and doc.name = 'WebHome' 仅选择空间主页,也可以使用受 PR 保护的$xwiki.search("select doc.space from XWikiDocument doc where doc.parent = '$rdoc2'"),但编程权限查询只能在极端情况下使用。
    猜你喜欢
    • 2013-06-10
    • 2015-12-28
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    相关资源
    最近更新 更多