Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Jun 09, 2011 @ 14:28
    Bjarne Fyrstenborg
    0

    Duplicate tree name

    I have a custom section News, where it has some trees..

    When I go to the News section from the Content section it first time shows it fine, but when I go to Content section and then back to News section the tree names are duplicated.

    For each time I switch between the Content and News section it seems to add the tree names once again and give the trees the same names.

    How can it be?

    Bjarne

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Jun 09, 2011 @ 14:45
    Richard Soeteman
    0

    Hi,

    I assume you create an XmlTreeNode  in  the render method of you content tree? Make sure you assign an Unique value to NodeId, not only for the tree but for the whole site if you don't do that. it will generate the behaviour you are having. Below a small example

     XmlTreeNode node = XmlTreeNode.Create(this);
    node.NodeID = menuItem.ID.ToString(); //This must be unique

    Thanks,

    Richard

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Jun 09, 2011 @ 15:05
    Bjarne Fyrstenborg
    0

    Hi Richard

    I have this in my code:

     

    using System;
    using System.Text;
    using umbraco.cms.presentation.Trees;
    namespace MyAssembly
    {
        public class loadNews : BaseTree
        {
            public loadNews(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 news tree
            /// 
            /// 
            public override void Render(ref XmlTree Tree)
            {
                // Create tree node to allow sending a newsletter
                var viewSubscribers = XmlTreeNode.Create(this);
                viewSubscribers.Text = "Vis tilmeldte";
                viewSubscribers.Icon = "docPic.gif";
                viewSubscribers.Action = "javascript:openViewSubscribers()";
                // Add the node to the tree
                Tree.Add(viewSubscribers);
                var sendNews = XmlTreeNode.Create(this);
                sendNews.Text = "Send nyhedsmail";
                sendNews.Icon = "docPic.gif";
                sendNews.Action = "javascript:openSendNews()";
                // Add the node to the tree
                Tree.Add(sendNews);
            }
            public override void RenderJS(ref StringBuilder Javascript)
            {
                Javascript.Append(@"
                    function openViewSubscribers() {
                        parent.right.document.location.href = 'news/viewSubscribers.aspx';
                    }
    ");
                Javascript.Append(@"
                    function openSendNews() {
                        parent.right.document.location.href = 'news/sendNews.aspx';
                    }
    ");
            }
        }
    }

    So it need the NodeID too? where do you get the unique value to the ID, in your example menuItem?
    I have worked from this example: 
    http://www.geckonewmedia.com/blog/2009/8/3/how-to-create-a-custom-section-in-umbraco-4

    I don't remember if it was a problem when I created a custom section in Umbraco 4.5.x but now I use Umbraco 4.7.

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    Jun 12, 2011 @ 01:37
    Bjarne Fyrstenborg
    0

    I looked at this solution from Morten http://our.umbraco.org/forum/developers/extending-umbraco/11345-Custom-tree-and-section-Text-duplicate-issue, which is much the same as you suggest Richard.

    I came to this solution:

    public override void Render(ref XmlTree Tree)
            {
                // Create tree node to allow sending a newsletter
                var viewSubscribers = XmlTreeNode.Create(this);
                viewSubscribers.NodeID = "uniqueViewSubscribers";
                viewSubscribers.Text = "Vis tilmeldte";
                viewSubscribers.Icon = "docPic.gif";
                viewSubscribers.Action = "javascript:openViewSubscribers()";
                viewSubscribers.Menu = null;
                // Add the node to the tree
                Tree.Add(viewSubscribers);
    
                var sendNews = XmlTreeNode.Create(this);
                sendNews.NodeID = "uniqueSendNews";
                sendNews.Text = "Send nyhedsmail";
                sendNews.Icon = "docPic.gif";
                sendNews.Action = "javascript:openSendNews()";
                sendNews.Menu = null;
                // Add the node to the tree
                Tree.Add(sendNews);
    
            }

    where I have added the NodeID and set the Menu attribute to null.
    Now it don't duplicate the text.

    Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft