DocumentTree in Javascript extension, Angular JS

I want to create a custom navigation menu using Angular JS and a skin extension. My current problem is that my mixed in Velocity doesn’t seem to be parsed. Here’s a snippet that i put into a JavaScriptExtension object:

var tree = #documentTree({
'showTranslations' : 'false',
"root" : "document:Products.WebHome",
"filterHiddenDocuments" : "true",
"showAttachments" : "false",
"compact" : "true" : 
"limit" : "25",
"openTo" : "document:$openToDoc"
});

console.log(tree);

This results in an uncaught exception since the resulting JS that is executed is exactly what is above; it’s not parsed. I’ve tried other Velocity snippets and they work.

I’ve also tried:

{{template name="documentTree_macros.vm" /}}

{{velocity}}
{{html}}
#documentTree({})
{{/html}}
{{/velocity}}

Which also isn’t parsed and the resulting JS is exactly as above.

Perhaps using a DocumentTree is not the optimal way for building a custom navigation menu? Maybe there is a way to loop through all of the documents in the wiki and use JS to create HTML elements for them. Or am I using Velocity wrong?

Thank you :slight_smile:!

Are you sure you’ve selected the xproperty inside the JavaScriptExtension xobject to parse Velocity?

ah wait you cannot do what you did :slight_smile:

A velocity macro has to start the line and cannot return a result, so the following cannot work:

var tree = #documentTree...
1 Like

Yes, I have chosen “Yes” on “Parse content”.
Allright, any suggestions as to how I could do it instead?

Perhaps the xwiki documentlist could be used? I can’t seem to be able to get it to be parsed though;

var docStuff = '$xwiki.wikimanager.getWikiDocumentList()';
console.log(docStuff);

prints “$xwiki.wikimanager.getWikiDocumentList()” to the console (and leaving out the quotes on the first line gives “Uncaught ReferenceError: $xwiki is not defined”.

If you use single quotes then you’re telling Velocity to not parse the content… see http://velocity.apache.org/engine/2.0/user-guide.html

Gotcha, I’m very new to Velocity. Doesn’t answer my question though. The problem is how to with JS (through perhaps Velocity) access information about which pages exist in the wiki.