cogList all spaces in the current wiki
Developed by

Vincent Massol

0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents


Outputs a list with links to each space in the current wiki (hidden spaces are excluded if the user has chosen not to list hidden documents - this is the default).


#foreach($space in $xwiki.spaces)
* [[$space>>$services.model.createDocumentReference('', $space, '')]]

Note 1: We call $services.model in order to handle special characters that may be in the space names, like spaces with dots ('.') in their name.
Note 2: We don't need to call $services.model.serialize($services.model.createDocumentReference('', $space, '')) because a DocumentReference's toString() method uses the default serializer to generate a string representation...
Note 3: In the future, XWiki should provide some API that returns a List<Space> and the Space object should have a method to return the space's home page reference. That would allow to write something like:

#foreach($spaceObject in <...some service to get the list of space objects...>)
* [[$>>$spaceObject.homeReference]]
Tags: code

Get Connected