Display Only Parent Pages In Space Menu

Last modified by Ecaterina Moraru (Valica) on 2021/03/18 11:28

cogCustomizes the Navigation Panel to display the first level of children pages for a space
TypeSnippet
Category
Developed by

Pascal Bastien

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

This page is confusing. It needs to be improved. If someone understands it, please edit and make sense of it. --VincentMassol

This code snippet tries to fix the following problem: the Navigation Panel lists all Pages in the wiki and this takes too long and displays too many pages on large wikis. This snippet only display 1 level of children pages.

You'll need to install the new version of the Document Tree Plugin before being able to use this code snippet.

Installing

Log in as admin and go to Panels->Panel wizard->Navigation->Navigation->Edit, and modify the following:

#set($hql = $xwiki.searchDocuments("doc.web='$space' order by doc.name"))

This has been tested with XWiki 1.1M2

Code

Modify the Navigation Panel with the following code:

#panelhiddenheader("Navigation")
#set ($hiddenSpaces = ["XWiki", "Admin", "Panels"])
#set ($hiddenPages = ["Main.WebRss", "Main.WebSearch", "Main.BlogRss", "Blog.Macros", "Main.TagsRss", "Main.RegisterNewUserAction", "Main.SpaceIndex", "Blog.Category"])
#set ($blackListedPages = ["WebPreferences"])
<div id="xwikinavcontainer">
#set($spaces = $xwiki.spaces)
#set($i = 0)
#set($spacecount = 0)
<div id="xwikinav">
#foreach($space in $spaces)
#if (!$hiddenSpaces.contains($space) || ($hiddenSpaces.contains($space) && $xwiki.hasAdminRights()))
#if ($doc.web == $space)
#set ($spacecount = $i)
#end
#set($i = $i + 1)
<div id="xwikinav${space}">
<div id="xwikinav${space}Header" class="accordionTabTitleBar"><h6>$space</h6></div>
<div id="xwikinav${space}Content" class="accordionTabContentBox">
#set($hql = $xwiki.searchDocuments("doc.web='$space' and (doc.parent is null or doc.parent='' or doc.name='WebHome') order by doc.name"))
#foreach($page in $hql)
#if (!$hiddenPages.contains($page) || ($hiddenPages.contains($page) && $xwiki.hasAdminRights()))
#set($dotIndex = $page.indexOf(".")+1)
#set($pageName = $page.substring($dotIndex, $page.length()))
#if (!$blackListedPages.contains($pageName) || ($blackListedPages.contains($pageName) && $xwiki.hasAdminRights()))
#if ($doc.fullName == $page)
- *$xwiki.getDocument($page).name*
#else
- [$page]
#end
#end
#end
#end
</div>
</div>
#end
#end
</div>
</div>
<script type="text/javascript">new Rico.Accordion( 'xwikinav', {panelHeight:'250',onLoadShowTab:'$spacecount'} );</script>
#panelfooter()

Result

Only Pages without Parent are display under Space in Panel Menu:

Img_NavigationPanel.jpg

MySpace contain this Pages:

Img_MySpaceMap.jpg

Pages MySpace.Map contain:

#includeInContext("Main.Plan")

and Main.Plan contain (inspired by ChildPageSnippet)

1 Plan de $doc.web

* [WebHome]

#set($tree = $xwiki.doctree.getSpaceDocumentTree($doc.web))

#set($depths=["", "*", "**", "***", "****", "*****", "******", "*******", "********"])

#foreach($leaf in $tree)
#if($leaf.depth <= 8 && \$leaf.depth != 0) $depths.get($leaf.depth) [$xwiki.getDocument($leaf.fullName).getDisplayTitle()>$leaf.fullName]
#end
#end

Get Connected