Changes for page Rangee Index
Last modified by Tobias Wintrich on 2025/10/31 08:26
From version 9.6
edited by Tobias Wintrich
on 2021/09/27 15:12
on 2021/09/27 15:12
Change comment:
There is no comment for this version
To version 17.1
edited by Tobias Wintrich
on 2025/10/14 16:36
on 2025/10/14 16:36
Change comment:
There is no comment for this version
Summary
-
Objects (1 modified, 1 added, 0 removed)
Details
- XWiki.WikiMacroClass[0]
-
- Context elements
-
... ... @@ -1,0 +1,1 @@ 1 +Sprache - Macro code
-
... ... @@ -1,34 +1,39 @@ 1 -{{tree links="true" icons="false" edges="false"}} 2 -{{velocity}} 3 -{{html wiki=true}} 4 -<ul> 5 -#foreach ($child in $doc.getChildrenReferences()) 6 - <li class="jstree-open"> 7 - [[$child]] 8 - <ul> 9 - #foreach ($subchild in $xwiki.getDocument($child).getChildren()) 10 - <li class="jstree-open"> 11 - [[$subchild]] 12 - <ul> 13 - #foreach ($subsubchild in $xwiki.getDocument($subchild).getChildren()) 14 - <li class="jstree-open"> 15 - [[$subsubchild]] 16 - <ul> 17 - #foreach ($subsubsubchild in $xwiki.getDocument($subsubchild).getChildren()) 18 - <li class="jstree-open"> 19 - [[$subsubsubchild]] 20 - </li> 21 - #end 22 - </ul> 23 - </li> 24 - #end 25 - </ul> 26 - </li> 27 - #end 28 - </ul> 29 - </li> 30 -#end 31 -</ul> 32 -{{/html}} 33 -{{/velocity}} 34 -{{/tree}} 1 +{{python}} 2 +from xwiki import XWikiContextProvider 3 + 4 +xcontext = XWikiContextProvider().get() 5 +xwiki = xcontext.getWiki() 6 +services = xcontext.services 7 +doc = xcontext.doc 8 +wikimacro = locals().get('wikimacro', None) 9 +depth = 0 10 +if wikimacro and wikimacro.parameters.get("depth"): 11 + depth = int(wikimacro.parameters.get("depth")) 12 + 13 +# Sprache bestimmen 14 +if str(xcontext.locale) == 'de': 15 + locale = '' 16 +else: 17 + locale = str(xcontext.locale) 18 + 19 +def get_children(parent_fullname): 20 + query = services.query.xwql("where doc.parent = :doc and doc.hidden = 0 order by doc.title asc") 21 + return query.bindValue("doc", parent_fullname).addFilter("currentlanguage").execute() 22 + 23 +def render_tree(parent_fullname, current_depth): 24 + html = "<ul>" 25 + for child_name in get_children(parent_fullname): 26 + rdoc = xwiki.getDocument(child_name).getTranslatedDocument() 27 + if locale == rdoc.getLanguage(): 28 + li_class = "" 29 + if current_depth > 0: 30 + li_class = "jstree-open" 31 + html += '<li class="' + li_class + '">[[{0}>>{1}]]</li>'.format(rdoc.getDisplayTitle(), rdoc.fullName) 32 + if current_depth < depth: 33 + html += render_tree(rdoc.fullName, current_depth + 1) 34 + html += "</ul>" 35 + return html 36 + 37 +print(render_tree(doc.fullName, 0)) 38 +{{/python}} 39 +
- XWiki.WikiMacroParameterClass[0]
-
- Parameter default value
-
... ... @@ -1,0 +1,1 @@ 1 +5 - Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +Öffne bis Ebene (0-5) - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +depth