Child Page Snippet

Prints a tree of child pages of the current document. If the current document is WebHome, the pages of the whole space are printed.

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

Code

#if($doc.name=="WebHome")
  #set($tree = $xwiki.doctree.getSpaceDocumentTree($doc.web))
#else
  #set($tree = $xwiki.doctree.getDocumentTree($doc))
#end
#set($depths=["", "*", "**", "***", "****", "*****", "******", "*******", "********"])

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

Result

  • ChildPage1
    • ChildPage2
    • ChildPage3
      • ChildPage4
    • ChildPage5
      • ChildPage6
      • ChildPage7
  • ChildPage8
Version 5.1 last modified by VincentMassol on 09/12/2007 at 13:43

Comments 4

greyfairer | 16.03.2007 at 04:37 PM
The Document Tree Plugin expects the parent property to only contain the document name, not the full name. However, XWiki will use the full name when creating a new page, and can handle both the full name and local name for parent property.

I'll try to fix it this weekend: let the plugin always return full names, and use parentDoc.fullName to compare in the snippet.

Better: let the plugin return some sort of a Composite Collection.


greyfairer | 18.03.2007 at 02:18 PM
See attachment: doctree 1.5, and include sample

FriedemannLoew | 20.03.2007 at 11:32 AM
Thank you very much for your changes, greyfairer. That's how I should have done it from the beginning.

I just readded the sorting of the document list before building the tree, so the nodes sorted in the tree. But now there's also the possibility to get an tree with unsorted nodes.

I'll put the new version to the Document Tree Plugin? when testing is finished


greyfairer | 20.03.2007 at 01:28 PM
Yes, I removed the sorting first, but forgot to put it back in somewhere.

Also, I didn't really test the getSpaceDocumentTree. It should return a tree with top document "" and all documents with empty parent on depth 1, but I don't know if it's really usefull that way or how you intended it to be?

Attachments 1

JAR
doctree-1.5.jar 1.2
PostedBy: greyfairer on 09/12/2007 (18kb )

Creator: FriedemannLoew on 2007/02/27 17:25
This wiki is licensed under a Creative Commons license
1.4.1.10194