Developer Forum »
Hide/Remove a node from default address
7 posts

Hi, is there a easy way to hide a node from the default address?

 

Example site hierarchy for node3:

Site 

--node1 (SectionPage)

----node2 (ContentType that should be hidden from default address)

------node3 (Article)

 

By default the Default address for node3 is /node1/node2/node3

But i want to hide node2 like this: /node1/node3

 

 

 

181 posts

Hi!

 

There is no way to hide a node from the default address if you use the "Include parents in address" setting. There are at least two solutions:

Override GetDefaultAddress, and create your own logic. This is best if this is a relatively common partern in your site. 

If this is a very specific instance, I would turn off automatic address, and change the address manually.

7 posts

Okey, I ended up with a property(ContentClassesProperty) in my ControlPanel. That way it is easy to choose what content types to hide.

Then i overrided the GetDefaultAddress() with this code:

Let me know if there is a better way of doing this :)

 

        public override string GetDefaultAddress()
        {
            var address = base.GetDefaultAddress();
            var classIds = this.GetUrlHiddenClassIds();

            if (classIds.Count() > 0) {
                var addressNames = new List();
                var parents = this.GetParents(this.Parent);

                for (int i = parents.Count() - 1; i >= 0; i--)
                {
                    var parent = parents.ElementAt(i);
                    if (!classIds.Contains(parent.ClassId))
                    {
                        addressNames.Add(Utils.GetAddressFriendlyName(parent.Name));
                    }
                }
                addressNames.Add(Utils.GetAddressFriendlyName(this.Name));

                address = string.Join("/", addressNames);
            }

            this.EnsureAddressUniqueness(address.ToLower());
            return address; 
        }

        public IEnumerable GetParents(NodeRelationPropertyValue parent)
        {
            while (parent.IsSet())
            {
                var hcParent = parent.Get();
                parent = hcParent.Parent;
                yield return hcParent;
            }
        }

        public UniqueList GetUrlHiddenClassIds()
        {
            var list = new UniqueList();
            var site = WAFRuntime.ContextSession.GetSite();
            if (site is SOS.Site.SOSBarnebyer)
            {
                var sosSite = (SOS.Site.SOSBarnebyer)site;
                if (sosSite.ControlPanel.IsSet())
                {
                    var cp = sosSite.ControlPanel.Get();
                    list = cp.UrlHiddenContentClasses.GetClassIds();
                }
            }
            return list;
        }
181 posts

I think this is a good solution, if you need to enable users to change the content types that should be hidden from the address.

1