Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Inx51 54 posts 107 karma points
    Nov 13, 2013 @ 01:06
    Inx51
    0

    How to create a custom BaseTree-tree?

    Hi! I found a snippet of some code of how to create a new Tree/BaseTree.. However.. I know that if you create a new section in Umbraco, umbraco then automatically adds the new section to the applications.config.. this BaseTree implementation didnt add anything to the trees.config.. so Im not quite sure if Im doing this the right way... also after manually manipulating the trees.config it seems like umbraco for some reason have created a context menu for me containing a create-action...

    This is my current code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Xml;
    using umbraco.BusinessLogic.Actions;
    using umbraco.cms.presentation.Trees;
    using umbraco.interfaces;
    using Umbraco.Core;
    using Umbraco.Web.Trees;
    
    namespace Site
    {
        [Tree(Constants.Applications.Developer, "udev", "UDev")]
        public class loadUDev : BaseTree
        {
            public loadUDev(string application)
                : base(application)
            { }
    
            protected override void CreateRootNode(ref XmlTreeNode rootNode)
            {
                rootNode.Icon = FolderIcon;
                rootNode.OpenIcon = FolderIconOpen;
                rootNode.NodeType = TreeAlias;
                rootNode.NodeID = "-1";
    
            }
            public override void RenderJS(ref StringBuilder Javascript)
            {
    
            }
    
            public override void Render(ref XmlTree tree)
            {
    
            }
        }
    }
    

    I guess I should mention that Im using Umbraco 7... but Im quite sure the approach for this is the same for 6 and 7 so all input is more than welcome!

    Br, Inx

  • Trung Vu 4 posts 24 karma points
    Dec 05, 2013 @ 12:56
    Trung Vu
    0

    You should change as follow:

    namespaceSite
    {
       
    [Tree(Constants.Applications.Developer,"udev","UDev", sortOrder: 1)]
       
    publicclass loadUDev :BaseTree
       
    {
           
    public loadUDev(string application)
               
    :base(application)
           
    {}

           
    protectedoverridevoidCreateRootNode(refXmlTreeNode rootNode)
           
    {
                rootNode
    .Icon=FolderIcon;
                rootNode
    .OpenIcon=FolderIconOpen;
                rootNode
    .NodeType=TreeAlias;
                rootNode
    .NodeID="-1";

           
    }
           
    publicoverridevoidRenderJS(refStringBuilderJavascript)
           
    {

           
    }

           
    publicoverridevoidRender(refXmlTree tree)
           
    {

           
    }

    protected override void CreateAllowedActions(ref List<IAction> actions)
    {
    actions.Clear();
    actions.Add(ActionNew.Instance);
    actions.Add(ActionDelete.Instance);
    actions.Add(ContextMenuSeperator.Instance);
    actions.Add(ActionRefresh.Instance);
    }
        }
    }

    Hope it work

  • Inx51 54 posts 107 karma points
    Dec 06, 2013 @ 15:50
    Inx51
    0

    Hi! Thanks for the reply, Still seems like umbraco wont add my new tree to the trees.config :(.. I still have to do that manually :(..

  • Trung Vu 4 posts 24 karma points
    Dec 06, 2013 @ 16:19
    Trung Vu
    0

    You should restart your application pool to check it work or not.

    For sure, let download their source code & find how did they do it: https://codeload.github.com/umbraco/Umbraco-CMS/zip/release-7.0.0

    Good luck

  • Inx51 54 posts 107 karma points
    Dec 06, 2013 @ 16:31
    Inx51
    0

    Hi! Yeah.. already checked that.. however.. it seems like the built project already contains a full-blown trees.config.. so maybe its not even supposed to be built up dynamically?.. can anyone confirm that?

    The problem is not that the new tree isnt displayed.. its is displayed and works great, the problem is that I manually have to add the

    Br, Inx

  • Trung Vu 4 posts 24 karma points
    Dec 06, 2013 @ 17:28
    Trung Vu
    0

    In my project, I can add my custom tree via code. And I'm sure the tree is built up dynamically. But about tree.config. I don't see any change

  • Inx51 54 posts 107 karma points
    Dec 12, 2013 @ 12:58
    Inx51
    0

    Hi again! Just copy pasted your code above to try it out.. and it doesn't seems to work in Umbraco v7 :( I added it in a an referenced assembly.. might that cause any problems? As far as my guess goes I would say that it shouldn't matter if HQ has done their part :)

Please Sign in or register to post replies

Write your reply to:

Draft