středa 22. října 2008

Using content/treemenu and mootools to retrieve eZ Publish node list

The following example illutrates use of content/treemenu function (normally used for admin interface content structure menu) to get a list of nodes, which can then be used to for instance filling select box.

The mooized code is as simple as this:
node_id = 2;
var jsonRequest = new Request.JSON({url: "http://site.com/content/treemenu/"+node_id, onComplete: function(result){
alert(result.children);
}}).get();

If you want to use it to fill select box options, following code will do the trick:

node_id = 2;
var jsonRequest = new Request.JSON({url: "http://site.com/content/treemenu/"+node_id, onComplete: function(result){

element = $('selectelement');
$each(result.children,function(item) {
element.options[element.options.length] = new Option(item.name,item.node_id);
});

}}).get();



To get this working correctly you need to allow contentstructure menu for your public site access and define classes you want to fetch (like this)
[TreeMenu]
Dynamic=enabled
ShowClasses[]=article
in contentstructuremenu.ini.append.php file.

Žádné komentáře: