List All Spaces
List all spaces in the current wiki |
Type | Snippet |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
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).
Code
#foreach($space in $xwiki.spaces)
* [[$space>>$services.model.createDocumentReference('', $space, '')]]
#end
{{/velocity}}
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.name>>$spaceObject.homeReference]]
#end
{{/velocity}}