Menu & Velocity Macro Problem

Hello people,
I use xwiki 14.1 and page syntax xwiki 2.1.
I try to make a menu with Menu Application but when i follow the examples eg:

{{menu type="vertical collapsible"}}
{{velocity}}
#set ($depth = 3)
#set ($limit = 10)
#macro (children $parentDoc $level)
  #foreach ($child in $parentDoc.getChildren($limit, 0))
    #set ($childDoc = $xwiki.getDocument($child))
    $stringtool.repeat('*', $level) {{html}}<a href="$childDoc.getURL()">$escapetool.xml($childDoc.plainTitle)</a>{{/html}}
    #if ($level < $depth)
      #children ($childDoc $mathtool.add($level, 1))
    #end
  #end
#end
#children ($doc 1)
{{/velocity}}
{{/menu}}

I get the following error:

Failed to execute the [velocity] macro. Cause: [Nested scripts are not allowed. Current Script Macro [velocity] (source [xwiki:Menu.MenuMacro]) is executed inside Script Macro [velocity] (source [xwiki:Menu.MenuMacro])]. Click on this message for details.

org.xwiki.rendering.macro.MacroExecutionException: Nested scripts are not allowed. Current Script Macro [velocity] (source [xwiki:Menu.MenuMacro]) is executed inside Script Macro [velocity] (source [xwiki:Menu.MenuMacro])
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:178)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:58)
 at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
 at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.transform(AbstractBlockAsyncRenderer.java:76)
 at org.xwiki.rendering.wikimacro.internal.DefaultWikiMacroRenderer.transform(DefaultWikiMacroRenderer.java:870)
 at org.xwiki.rendering.wikimacro.internal.DefaultWikiMacroRenderer.transform(DefaultWikiMacroRenderer.java:856)
 at org.xwiki.rendering.wikimacro.internal.DefaultWikiMacroRenderer.transform(DefaultWikiMacroRenderer.java:589)
 at org.xwiki.rendering.wikimacro.internal.DefaultWikiMacroRenderer.execute(DefaultWikiMacroRenderer.java:404)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:157)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:54)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.lambda$syncRender$0(DefaultAsyncRendererExecutor.java:267)
 at com.xpn.xwiki.internal.security.authorization.DefaultAuthorExecutor.call(DefaultAuthorExecutor.java:98)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:267)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.execute(DefaultBlockAsyncRendererExecutor.java:125)
 at org.xwiki.rendering.wikimacro.internal.DefaultWikiMacro.execute(DefaultWikiMacro.java:110)
 at org.xwiki.rendering.wikimacro.internal.DefaultWikiMacro.execute(DefaultWikiMacro.java:53)
 at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
 at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
 at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:88)
 at org.xwiki.display.internal.DocumentContentAsyncExecutor.executeInCurrentExecutionContext(DocumentContentAsyncExecutor.java:348)
 at org.xwiki.display.internal.DocumentContentAsyncExecutor.execute(DocumentContentAsyncExecutor.java:221)
 at org.xwiki.display.internal.DocumentContentAsyncRenderer.execute(DocumentContentAsyncRenderer.java:107)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:157)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:54)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:273)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.execute(DefaultBlockAsyncRendererExecutor.java:125)
 at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:67)
 at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:43)
 at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:96)
 at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:39)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:123)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:52)
 at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:68)
 at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:42)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:1228)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1532)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1462)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1416)
 at com.xpn.xwiki.api.Document.getRenderedContent(Document.java:866)
 at com.xpn.xwiki.api.Document.getRenderedContent(Document.java:839)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:571)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:554)
 at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:221)
 at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:368)
 at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:492)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.apache.velocity.runtime.parser.node.ASTElseIfStatement.render(ASTElseIfStatement.java:108)
 at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:190)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.Template.merge(Template.java:358)
 at org.apache.velocity.Template.merge(Template.java:262)
 at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:280)
 at com.xpn.xwiki.render.DefaultVelocityManager.evaluate(DefaultVelocityManager.java:321)
 at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:131)
 at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:52)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.evaluateBlock(AbstractScriptMacro.java:286)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:182)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:58)
 at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
 at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
 at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:88)
 at org.xwiki.display.internal.DocumentContentAsyncExecutor.executeInCurrentExecutionContext(DocumentContentAsyncExecutor.java:348)
 at org.xwiki.display.internal.DocumentContentAsyncExecutor.execute(DocumentContentAsyncExecutor.java:221)
 at org.xwiki.display.internal.DocumentContentAsyncRenderer.execute(DocumentContentAsyncRenderer.java:107)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:157)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:54)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:273)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.execute(DefaultBlockAsyncRendererExecutor.java:125)
 at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:67)
 at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:43)
 at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:96)
 at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:39)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:123)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:52)
 at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:68)
 at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:42)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:1228)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1532)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1462)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1445)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1430)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1386)
 at com.xpn.xwiki.objects.classes.PropertyClass.lambda$renderContentInContext$0(PropertyClass.java:376)
 at com.xpn.xwiki.internal.security.authorization.DefaultAuthorExecutor.call(DefaultAuthorExecutor.java:98)
 at com.xpn.xwiki.objects.classes.PropertyClass.renderContentInContext(PropertyClass.java:376)
 at com.xpn.xwiki.objects.classes.PropertyClass.displayCustom(PropertyClass.java:324)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:3574)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:3508)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:3441)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:3427)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:3404)
 at com.xpn.xwiki.api.Document.display(Document.java:1657)
 at jdk.internal.reflect.GeneratedMethodAccessor466.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:571)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:554)
 at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:221)
 at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:368)
 at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:492)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.Template.merge(Template.java:358)
 at org.apache.velocity.Template.merge(Template.java:262)
 at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:280)
 at com.xpn.xwiki.render.DefaultVelocityManager.evaluate(DefaultVelocityManager.java:321)
 at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:131)
 at org.xwiki.rendering.internal.macro.velocity.VelocityMacro.evaluateString(VelocityMacro.java:52)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.evaluateBlock(AbstractScriptMacro.java:286)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:182)
 at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:58)
 at org.xwiki.rendering.internal.transformation.macro.MacroTransformation.transform(MacroTransformation.java:297)
 at org.xwiki.rendering.internal.transformation.DefaultRenderingContext.transformInContext(DefaultRenderingContext.java:183)
 at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:88)
 at org.xwiki.display.internal.DocumentContentAsyncExecutor.executeInCurrentExecutionContext(DocumentContentAsyncExecutor.java:348)
 at org.xwiki.display.internal.DocumentContentAsyncExecutor.execute(DocumentContentAsyncExecutor.java:221)
 at org.xwiki.display.internal.DocumentContentAsyncRenderer.execute(DocumentContentAsyncRenderer.java:107)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:157)
 at org.xwiki.rendering.async.internal.block.AbstractBlockAsyncRenderer.render(AbstractBlockAsyncRenderer.java:54)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:273)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.execute(DefaultBlockAsyncRendererExecutor.java:125)
 at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:67)
 at org.xwiki.display.internal.DocumentContentDisplayer.display(DocumentContentDisplayer.java:43)
 at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:96)
 at org.xwiki.display.internal.DefaultDocumentDisplayer.display(DefaultDocumentDisplayer.java:39)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:245)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.applySheet(SheetDocumentDisplayer.java:225)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.maybeDisplayWithSheet(SheetDocumentDisplayer.java:180)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:111)
 at org.xwiki.sheet.internal.SheetDocumentDisplayer.display(SheetDocumentDisplayer.java:52)
 at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:68)
 at org.xwiki.display.internal.ConfiguredDocumentDisplayer.display(ConfiguredDocumentDisplayer.java:42)
 at com.xpn.xwiki.doc.XWikiDocument.display(XWikiDocument.java:1228)
 at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:1365)
 at com.xpn.xwiki.doc.XWikiDocument.displayDocument(XWikiDocument.java:1314)
 at com.xpn.xwiki.doc.XWikiDocument.displayDocument(XWikiDocument.java:1283)
 at com.xpn.xwiki.api.Document.displayDocument(Document.java:794)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:571)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:554)
 at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:221)
 at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:368)
 at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:704)
 at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:75)
 at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:242)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:190)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.xwiki.velocity.internal.directive.TryCatchDirective.render(TryCatchDirective.java:86)
 at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:304)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.Template.merge(Template.java:358)
 at org.apache.velocity.Template.merge(Template.java:262)
 at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:280)
 at com.xpn.xwiki.render.DefaultVelocityManager.evaluate(DefaultVelocityManager.java:321)
 at com.xpn.xwiki.internal.template.VelocityTemplateEvaluator.evaluateContent(VelocityTemplateEvaluator.java:95)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.evaluateContent(TemplateAsyncRenderer.java:225)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.renderVelocity(TemplateAsyncRenderer.java:180)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.render(TemplateAsyncRenderer.java:137)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.render(TemplateAsyncRenderer.java:53)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.lambda$syncRender$0(DefaultAsyncRendererExecutor.java:267)
 at com.xpn.xwiki.internal.security.authorization.DefaultAuthorExecutor.call(DefaultAuthorExecutor.java:98)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:267)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.render(DefaultBlockAsyncRendererExecutor.java:154)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:772)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:745)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:725)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:711)
 at com.xpn.xwiki.internal.template.DefaultTemplateManager.render(DefaultTemplateManager.java:78)
 at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:2509)
 at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:2487)
 at com.xpn.xwiki.api.XWiki.parseTemplate(XWiki.java:997)
 at jdk.internal.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:571)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:554)
 at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:221)
 at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:368)
 at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:492)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:218)
 at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:331)
 at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:261)
 at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:304)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.Template.merge(Template.java:358)
 at org.apache.velocity.Template.merge(Template.java:262)
 at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:280)
 at com.xpn.xwiki.render.DefaultVelocityManager.evaluate(DefaultVelocityManager.java:321)
 at com.xpn.xwiki.internal.template.VelocityTemplateEvaluator.evaluateContent(VelocityTemplateEvaluator.java:95)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.evaluateContent(TemplateAsyncRenderer.java:225)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.renderVelocity(TemplateAsyncRenderer.java:180)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.render(TemplateAsyncRenderer.java:137)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.render(TemplateAsyncRenderer.java:53)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.lambda$syncRender$0(DefaultAsyncRendererExecutor.java:267)
 at com.xpn.xwiki.internal.security.authorization.DefaultAuthorExecutor.call(DefaultAuthorExecutor.java:98)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:267)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.render(DefaultBlockAsyncRendererExecutor.java:154)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:772)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:745)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:725)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:711)
 at com.xpn.xwiki.internal.template.DefaultTemplateManager.render(DefaultTemplateManager.java:78)
 at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:2509)
 at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:2487)
 at com.xpn.xwiki.api.XWiki.parseTemplate(XWiki.java:997)
 at jdk.internal.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:571)
 at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:554)
 at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:221)
 at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:368)
 at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:492)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:218)
 at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:331)
 at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:261)
 at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:304)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:171)
 at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:147)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:190)
 at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:439)
 at org.apache.velocity.Template.merge(Template.java:358)
 at org.apache.velocity.Template.merge(Template.java:262)
 at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:280)
 at com.xpn.xwiki.render.DefaultVelocityManager.evaluate(DefaultVelocityManager.java:321)
 at com.xpn.xwiki.internal.template.VelocityTemplateEvaluator.evaluateContent(VelocityTemplateEvaluator.java:95)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.evaluateContent(TemplateAsyncRenderer.java:225)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.renderVelocity(TemplateAsyncRenderer.java:180)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.render(TemplateAsyncRenderer.java:137)
 at com.xpn.xwiki.internal.template.TemplateAsyncRenderer.render(TemplateAsyncRenderer.java:53)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.lambda$syncRender$0(DefaultAsyncRendererExecutor.java:267)
 at com.xpn.xwiki.internal.security.authorization.DefaultAuthorExecutor.call(DefaultAuthorExecutor.java:98)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.syncRender(DefaultAsyncRendererExecutor.java:267)
 at org.xwiki.rendering.async.internal.DefaultAsyncRendererExecutor.render(DefaultAsyncRendererExecutor.java:250)
 at org.xwiki.rendering.async.internal.block.DefaultBlockAsyncRendererExecutor.render(DefaultBlockAsyncRendererExecutor.java:154)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:772)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:745)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.renderFromSkin(InternalTemplateManager.java:725)
 at com.xpn.xwiki.internal.template.InternalTemplateManager.render(InternalTemplateManager.java:711)
 at com.xpn.xwiki.internal.template.DefaultTemplateManager.render(DefaultTemplateManager.java:78)
 at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:2509)
 at com.xpn.xwiki.web.Utils.parseTemplate(Utils.java:179)
 at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:606)
 at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:289)
 at com.xpn.xwiki.web.LegacyActionServlet.service(LegacyActionServlet.java:115)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
 at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1411)
 at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1631)
 at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:122)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
 at org.xwiki.wysiwyg.filter.ConversionFilter.doFilter(ConversionFilter.java:61)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
 at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
 at org.xwiki.container.servlet.filters.internal.SetHTTPHeaderFilter.doFilter(SetHTTPHeaderFilter.java:63)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
 at org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:208)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
 at org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
 at org.xwiki.resource.servlet.RoutingFilter.doFilter(RoutingFilter.java:132)
 at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
 at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:549)
 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
 at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
 at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
 at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
 at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
 at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
 at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1369)
 at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
 at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)
 at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
 at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
 at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1284)
 at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
 at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
 at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
 at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
 at org.eclipse.jetty.server.Server.handle(Server.java:501)
 at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
 at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
 at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
 at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
 at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
 at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
 at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
 at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
 at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
 at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
 at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
 at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
 at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
 at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
 at java.base/java.lang.Thread.run(Thread.java:834)

What could I have done so wrong? I’m sorry if it is simple but I’m new to xwiki.

So what has happened here is that you are trying to pass a Velocity script directly into the Menu macro, which itself consists of a Velocity script. (To see what I mean, open Menu.MenuMacro in the objects editor and take a look at the WikiMacroClass object in there.) XWiki does not currently support nested Velocity scripts.

Are you trying to make a menu that is specific to one wiki page, or are you trying to make a menu that will go into a panel or under the wiki header?

If you are making a wiki-wide menu, you should create the menu using the Menu Application directly, as this will do most of the necessary configuration/inclusions for you. To do this, go to the Administration Application (“Administer Wiki”), then “Look & Feel”, then “Menus”, then click on “Add New Entry” next to the table. (These strings are obviously from the English localization; they may differ for you.) This will bring you to the editor for your new menu’s document content. This is where your Velocity script should go, sans {{menu}}. Make sure you then add the document’s fullname (e.g. Menu.MyMenu) to the appropriate “Panels displayed…” field in the Administration Application’s Panels section.

If you are just creating a menu to embed in one page, you’ll actually want to put the {{velocity}} tags outside the Menu macro call, like so:

{{velocity}}
{{menu type="vertical collapsible"}}
#set ($depth = 3)
#set ($limit = 10)
#macro (children $parentDoc $level)
  #foreach ($child in $parentDoc.getChildren($limit, 0))
    #set ($childDoc = $xwiki.getDocument($child))
    $stringtool.repeat('*', $level) {{html}}<a href="$childDoc.getURL()">$escapetool.xml($childDoc.plainTitle)</a>{{/html}}
    #if ($level < $depth)
      #children ($childDoc $mathtool.add($level, 1))
    #end
  #end
#end
#children ($doc 1)
{{/menu}}
{{/velocity}}

This fixes the problem because then you are not passing another script into the macro’s Velocity script, and the renderer can still recognize that there is Velocity code to parse. (I believe that the Velocity macro has higher priority than the Menu macro.)

Thank you for your response @SightSpirit.

Are you trying to make a menu that is specific to one wiki page, or are you trying to make a menu that will go into a panel or under the wiki header?

I’m trying to make a menu that will go into a panel. Well I’m not trying, I have already made it.

But i couldn’t find the way to combine velocity and menu macros… Thank you very much.
I put the velocity ‘outside’ and I believe that make the trick (the examples in Menu App must be corrected).

Now i have a really annoying problem that doesn’t solved even with velocity macro :frowning_face:. The collapsible option doesn’t work.
On the panel, when loading an xwiki page, my menu is always open! But on the Menu App editor page, it is closed which is the correct function.
A part of my code:

{{velocity}}
{{menu type="vertical collapsible"}}

* [[Home>>Main.WebHome]]
#if ($hasAdmin)
* [[Introduction>>Introduction.WebHome]]
#end
* [[R&D Services>>R&D Services.WebHome]]
** [[Access to data>>R&D Services.Access to data.WebHome]]
** [[Capacity building>>R&D Services.Capacity building.WebHome]]
** [[Clinical trials>>R&D Services.Clinical trials.WebHome]]
** [[Co-creation session>>R&D Services.Co-creation session.WebHome]]
* [[Devices and technologies>>Devices and technologies.WebHome]]

{{/menu}}
{{/velocity}}

So, if the velocity macro couldn’t solve this… Do you have any ideas?

Hi, @Sarantis. Glad to hear that switching up the tag order helped!

I am not sure exactly why it is disobeying your type values, but when I made my own custom, load-collapsed menu, I didn’t include the {{menu}} macro in my code.

My Menu Code (excerpt)
  #set( $thisDoc = $doc.getDocumentReference() )
  #set( $adminDoc = $preferencesDoc.getDocumentReference() )
  #if( $inModGroup && !$hasAdmin)
    ##* [[Change Requests>>ChangeRequest.WebHome]] ## Removed Change Requests app due to instability; may reinstall after extension's beta
  #end
  #if( $hasAdmin )
    * Applications
      ** [[Admin Module>>XWiki.XWikiPreferences]]
        *** [[Extensions>>XWiki.XWikiPreferences||queryString="editor=globaladmin&section=XWiki.Extensions"]]
        *** [[Menus>>XWiki.XWikiPreferences||queryString="editor=globaladmin&section=menu.name"]]
      ** [[Invitation Sender>>Invitation.WebHome]]
      ** [[Recycle Bin>>Main.AllDocs||queryString="view=deletedDocs"]]
      ##** [[Change Requests>>ChangeRequest.WebHome]] ## Removed Change Requests app due to instability; may reinstall after extension's beta
  #end
  #if( $thisDoc != $adminDoc && !$thisDoc.toString().endsWith('WebPreferences') )
    * Page Utilities
    #set( $objectEdit = $xcontext.getURLFactory().getServerURL($xcontext.context) + $doc.getURL('edit','editor=object') )
    #set( $classEdit = $xcontext.getURLFactory().getServerURL($xcontext.context) + $doc.getURL('edit','editor=class') )
    #set( $source = $xcontext.getURLFactory().getServerURL($xcontext.context) + $doc.getURL('view','viewer=code') )
    #set( $history = $xcontext.getURLFactory().getServerURL($xcontext.context) + $doc.getURL('view','viewer=history') )
      ** [[Objects Editor>>$objectEdit]]
      ** [[Class Editor>>$classEdit]]
      ** [[Page History>>$history]]
      ** [[View Source>>$source]]
  #end

When you create a menu using the application, it creates an XWikiUIExtensionClass object under the menu’s page for you. This contains the code that the panel actually calls to render the menu, and this is where the {{menu}} macro is called. As such, you should modify that object’s macro call to include a “collapsible” type.

My XWikiUIExtensionClass Object Code
{{velocity}}
  #set( $inModGroup = $xwiki.getUser($xcontext.user).isUserInGroup('XWiki.XWikiModGroup') )
  #if( $hasAdmin )
    #panelheader("Admin CP")
    {{menu type="vertical collapsible"}}{{include reference="$xcontext.uix.doc.documentReference" /}}{{/menu}}
    #panelfooter()
  #elseif( $inModGroup )
    #panelheader("Moderator CP")
    {{menu type="vertical collapsible"}}{{include reference="$xcontext.uix.doc.documentReference" /}}{{/menu}}
    #panelfooter()
  #else
  #end
{{/velocity}}

Oh I really thank you!! The XWikiUIExtensionClass , on my menus i have created, had the current block of code:

{{menu type="vertical collapsible open"}}

So i just delete the open and you were right about {{menu}} macro, doesn’t needed at all in the code.
All run good for now. In a simple way of course…

1 Like