Missing Root Node in Umbraco V7 Custom Section Tree
Hi All
I'm trying to follow the "modern" method of creating a tree in a custom section. I can't seem to get the root ndoe to appear though, and it's driving me mad.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.businesslogic;
using umbraco.interfaces;
namespace myproject.BusinessLogic
{
[Application("ClientZone", "ClientZone", "icon-file-cabinet", 15)]
public class ClientZoneApplication : IApplication { }
}
and it generates the following in /config/applications.config
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
namespace myproject.BusinessLogic
{
[PluginController("ClientZone")]
[Umbraco.Web.Trees.Tree("ClientZone", "ClientZoneTree", "Client Zone", iconClosed: "icon-folder")]
public class ClientZoneTreeController : TreeController
{
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection();
var item = this.CreateTreeNode("dashboard", id, queryStrings, "My item", "icon-truck", true);
nodes.Add(item);
return nodes;
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
//menu.DefaultMenuAlias = ActionNew.Instance.Alias;
//menu.Items.Add<ActionNew>("Create");
return menu;
}
}
}
and here is what is generated in my /config/trees.config
Now I would expect this to generate a folder icon with the word "Client Zone" next to it. Clicking on that should open up the tree to display a truck icon and the phrase "my item".
However, all I get is the truck Icon. No Root. No folder. :(
I've been all over it and can't see what I'm doing wrong. Can anyone help?
Have you checked that your user is actually allowed to see the section you're adding?
This got me when I was playing around with adding custom sections and trees - I was pulling my hair of untill Warren Buckley said..."Have you given your user access to the section?"...So try to check...that's probably it...so simple...so frustrating! :D
Thanks for your reply. Yeah, I have the section set to visible on the user. I can see the section icon and click through to the section. It's just the root node doesn't appear.
I've found a way around the problem. I can set up a new node using CreateTreeNode inside my TreeNodeCollection, and use that as my root.
From what I can see there is no solution as such, it's just that the functionality of the treenodes doesn't match what is laughably described as the documentation.
In the end I went for this approach.
[Tree("mycustomsection", "mycustomsectiontree", "my custom section")]
[PluginController("mycustomsection")]
public class mycustomsectionTreeController : TreeController {
I'm not using all the attribute properties as suggested in the earlier links, as they don't do anything, I am setting a plugincontroller though, to keep all my code neat.
This next bit occurs immediately inside the treecontroller class. If it doesn't work it's because I'm having to anonymise it, and simplify it as i copy n paste it over.
protected override Umbraco.Web.Models.Trees.TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{ var tree = new Umbraco.Web.Models.Trees.TreeNodeCollection(); //check if we're rendering the root node
if (id == Constants.System.Root.ToInvariantString())
{ var RootNode = CreateTreeNode("1", "-1", queryStrings, "my root node");
RootNode.HasChildren = true;
tree.Add(RootNode); } else if(id == "1")
{ //this is a child of the root node var childnode = CreateTreeNode("1-1", "1", queryStrings, "my first child node"); var otherchildnode = CreateTreeNode "1-2", "1", queryStrings "my second child node"); tree.Add(childnode); tree.Add(otherchildnode); } else if(id.StartsWith("1-")) { //this must be a third level node, e.g. one that's under the child nodes. } return tree;
//this tree doesn't suport rendering more than 1 level
throw new NotSupportedException(); }
Missing Root Node in Umbraco V7 Custom Section Tree
Hi All
I'm trying to follow the "modern" method of creating a tree in a custom section. I can't seem to get the root ndoe to appear though, and it's driving me mad.
I've taken a lot from here
http://www.enkelmedia.se/blogg/2013/11/22/creating-custom-sections-in-umbraco-7-part-1.aspx
Here is my Application class
and it generates the following in /config/applications.config
Here is my tree controller class
and here is what is generated in my /config/trees.config
Now I would expect this to generate a folder icon with the word "Client Zone" next to it. Clicking on that should open up the tree to display a truck icon and the phrase "my item".
However, all I get is the truck Icon. No Root. No folder. :(
I've been all over it and can't see what I'm doing wrong. Can anyone help?
Hi Shaun
Have you checked that your user is actually allowed to see the section you're adding?
This got me when I was playing around with adding custom sections and trees - I was pulling my hair of untill Warren Buckley said..."Have you given your user access to the section?"...So try to check...that's probably it...so simple...so frustrating! :D
/Jan
Hi Jan
Thanks for your reply. Yeah, I have the section set to visible on the user. I can see the section icon and click through to the section. It's just the root node doesn't appear.
I've found a way around the problem. I can set up a new node using CreateTreeNode inside my TreeNodeCollection, and use that as my root.
What is odd is that this line here...
...doesn't seem to create the root node, which is strange, as from the parameters being sent to it, you'd expect it to generate one.
Hi Shaun,
Did you ever solve this? As i'm running into the same problem and cant find a resolution anywhere :(
Thanks,
Tom
Hi Tom
From what I can see there is no solution as such, it's just that the functionality of the treenodes doesn't match what is laughably described as the documentation.
In the end I went for this approach.
I'm not using all the attribute properties as suggested in the earlier links, as they don't do anything, I am setting a plugincontroller though, to keep all my code neat.
This next bit occurs immediately inside the treecontroller class. If it doesn't work it's because I'm having to anonymise it, and simplify it as i copy n paste it over.
It's a bit clunky, but it does the job.
is working on a reply...