I'm trying to create an automatic Index where all the pages from the spaces will be displayed. Something like:
Where:
Read=True
) user can click to access the content.Read=False
) user can see the title but can't click.If the user has no rights to read
the page I want that at least he can get to see the title of the page as I can continue listing the pages that are able to read
in the child.
What I have:
#foreach($space in $xwiki.spaces)
#set($WebHome = $space + ".WebHome")
#getChildrenOf($WebHome)
#end
Now the recursive getChildrenOf
macro is:
#macro(getChildrenOf, $docName)
#foreach($name in $xwiki.searchDocuments('where doc.parent = ? or doc.parent = ? order by doc.name', [$docName, "xwiki:$docName"]))
#if($xwiki.hasAccessLevel('view', "xwiki:$name"))
[[$xwiki.getDocument($name).getPlainTitle()>>$name]]
#else
$xwiki.getDocument($name).getPlainTitle()
#end
#getChildrenOf($name)
#end
#end
Results:
In the else
i'm getting a plain text showing the function $xwiki.getDocument($name).getPlainTitle()
instead of the title of the Page.
If I just write $name
in the else
what I get is: Space_1.Page_2
instead of the title of Page 2.
Why is that happening? How can I solve it?
$xwiki.getDocument($name)
return null when the current user does not have view right on $name and when a method return null Velocity behavior is to display the code.
You can use $xwiki.getDocumentAsAuthor($name)
instead to access the document with the right of the script's author. See http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org/xwiki/platform/xwiki-platform-oldcore/6.2/xwiki-platform-oldcore-6.2-javadoc.jar/!/com/xpn/xwiki/api/XWiki.html#getDocumentAsAuthor%28org.xwiki.model.reference.DocumentReference%29