Hi there! I'm fairly new to Umbraco development and still learning. While creating a website for a customer I found the need to create a custom section called "Tools", the tools contains folders and nodes like the structure below:
- Tools (RoodNode) - Client (Folder) - Some node - Some node
So creating the section including the nodes wasn't a big problem, everything works like a charm.
Now the hard part where I got stuck :-P In de User section each user has the option to set a startnode for the content and a startnode for the media. How can I create a option so I can set the startnode for the Tools section for each user?
I hope someone can help me out here, I'v been Googling for ages now but couldn't find a solution.
When you're rendering your custom tree you can hide nodes that are not accessable to the user, or use some logic before you render the tree to only render what that current user can see.
There's nothing 'out the box' which will allow you to set a start node for a custom section.
I've create a new User Type, in this example I called it "Custom User", then I check if the loggedin user is the Admin or is a Custom User.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using umbraco.cms.presentation.Trees; using System.Web; using umbraco.BusinessLogic;
namespace MyCustomTools { public class LoadCustomTools : BaseTree { public LoadCustomTools(string application) : base(application) { }
Start Node in Media Library
Hi there! I'm fairly new to Umbraco development and still learning.
While creating a website for a customer I found the need to create a custom section called "Tools", the tools contains folders and nodes like the structure below:
- Tools (RoodNode)
- Client (Folder)
- Some node
- Some node
So creating the section including the nodes wasn't a big problem, everything works like a charm.
Now the hard part where I got stuck :-P
In de User section each user has the option to set a startnode for the content and a startnode for the media.
How can I create a option so I can set the startnode for the Tools section for each user?
I hope someone can help me out here, I'v been Googling for ages now but couldn't find a solution.
Cheers, Dwight
Hey Dwight,
When you're rendering your custom tree you can hide nodes that are not accessable to the user, or use some logic before you render the tree to only render what that current user can see.
There's nothing 'out the box' which will allow you to set a start node for a custom section.
Rich
Hey Rich,
thanks for the reply. Do you know where to find some sample code to render only what is accessible to the user?
Dwight
Hey Dwight,
Am I correct in thinking that you are rendering the nodes via some custom c#?
There's no example to show because the solution is solely for your project.
The logic would be something like
if (UmbracoUserGroup = x)
{renderNode}
I might be missing something here so sorry if so, if not you should be able to work the logic out I think?
Rich
I found the solution!
I've create a new User Type, in this example I called it "Custom User", then I check if the loggedin user is the Admin or is a Custom User.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using umbraco.cms.presentation.Trees;
using System.Web;
using umbraco.BusinessLogic;
namespace MyCustomTools
{
public class LoadCustomTools : BaseTree
{
public LoadCustomTools(string application)
: base(application)
{ }
protected override void CreateRootNode(ref XmlTreeNode rootNode)
{
rootNode.Icon = FolderIcon;
rootNode.OpenIcon = FolderIconOpen;
rootNode.NodeType = "init" + TreeAlias; rootNode.NodeID = "init";
}
/// Override the render method to create the custom tree
public override void Render(ref XmlTree Tree)
{
User user = User.GetCurrent();
if (user.IsAdmin() || user.UserType.Alias == "Custom User")
{
if (this.id == this.StartNodeID)
{
var Folder = XmlTreeNode.Create(this);
Folder.NodeID = "2";
Folder.Text = "Custom Folder";
Folder.Icon = FolderIcon;
Folder.OpenIcon = FolderIconOpen;
Folder.HasChildren = true;
Folder.Source = this.GetTreeServiceUrl(2);
Tree.Add(Folder);
} else if (this.id == 2) {
var customNode = XmlTreeNode.Create(this);
customNode.Text = "My Custom Node";
customNode.Icon = "docPic.gif";
customNode.Action = "javascript:openCustomNode()";
Tree.Add(customNode);
}
}
}
public override void RenderJS(ref StringBuilder Javascript) {
Javascript.Append(@"
function openCustomNode() {
parent.right.document.location.href = '/handlers/somehandler.aspx';
}
");
}
}
}
Nice, glad you got it working :)
Rich
is working on a reply...