Easy Tree View with all spaces and children

Last modified by Vincent Massol on 2017/08/09 15:48

Here is an easy way to create Tree View that lists spaces and their children in a tree view in panel without any problem.

It is using mktree extension that could be found here
http://extensions.xwiki.org/xwiki/bin/view/Extension/Mktree+Application

{{velocity}}
{{html wiki="true"}}
$xwiki.ssx.use("XWiki.mktree")
$xwiki.jsx.use("XWiki.mktree")
<ul name ="anyname" class="mktree">
#set ($spaces = $xwiki.spaces)
#foreach ($space in $spaces)
#if ($hasAdmin || ($xwiki.hasAccessLevel('view', "${space}.WebHome") && !$blacklistedSpaces.contains($space)))
#if ($foreach.index > 0)
(% class="pitemseparator" %) ~| (%%)##
#end
#set($query="where doc.fullName='${space}.WebHome'")
#set($results = false)
#set($results = $xwiki.searchDocuments($query, 10, 0))
#foreach($docname in $results)
#set($rdoc = $xwiki.getDocument($docname).getTranslatedDocument())
<li>
[[$rdoc.getDisplayTitle()>>$rdoc.fullName]]
</li>
#set($query2="where doc.parent='$rdoc'")
#set($results2 = false)
#set($results2 = $xwiki.searchDocuments($query2, 10, 0))
<ul>
#foreach($rdoc in $results2)
#set($rdoc2 = $xwiki.getDocument($rdoc).getTranslatedDocument())
<li>
[[$rdoc2.getDisplayTitle()>>$rdoc2.fullName]]
</li>
#set($query3="where doc.parent='$rdoc2'")
#set($results3 = false)
#set($results3 = $xwiki.searchDocuments($query3, 10, 0))
<ul>
#foreach($rdoc2 in $results3)
#set($rdoc3 = $xwiki.getDocument($rdoc2).getTranslatedDocument())
<li>
[[$rdoc3.getDisplayTitle()>>$rdoc3.fullName]]
</li>
#set($query4="where doc.parent='$rdoc3'")
#set($results4 = false)
#set($results4 = $xwiki.searchDocuments($query4, 10, 0))
<ul>
#foreach($rdoc3 in $results4)
#set($rdoc4 = $xwiki.getDocument($rdoc3).getTranslatedDocument())
<li>
[[$rdoc4.getDisplayTitle()>>$rdoc4.fullName]]
</li>
#set($query5="where doc.parent='$rdoc4'")
#set($results5 = false)
#set($results5 = $xwiki.searchDocuments($query5, 10, 0))
<ul>
#foreach($rdoc4 in $results5)
#set($rdoc5 = $xwiki.getDocument($rdoc4).getTranslatedDocument())
<li>
[[$rdoc5.getDisplayTitle()>>$rdoc5.fullName]]
</li>
#end
</ul>
#end
</ul>
#end
</ul>
#end
</ul>
#end
#end
#end
{{/html}}
{{/velocity}}
Tags:
    

Get Connected