How to add new Zones

Apr 5, 2008 at 1:57 AM
How I can customize the zones for the master page?
I'm new user from this cms!
Great work
Coordinator
Apr 5, 2008 at 10:50 PM

christiangilbert wrote:
How I can customize the zones for the master page?
I'm new user from this cms!
Great work


Hi Christian (nice name)

There's two things needed for using zones

Defining zones and parts in your cms model

Adding a control to the template that renders them

Hope this makes any sense. Please tell otherwise

/Cristian
Aug 20, 2009 at 2:54 PM

Hi guys,

I was just thinking while this explains how to create items and parts, and how to name a zone in the aspx. The actual Zone names are part of the N2 source are they not? So for example, if you wanted to have four columns which held the zones: Right, Left, Content and Content2 say, when you define your item in the class file, how could you say [AllowedZones()] (or whatever its called)  and use Content2 ?

I think I might be confused slightly between the idea of 'pages' and the use of parts.. There are pages such as Event Page, which has a purpose to show events. But if the client wants something like news and events in one.. with RSS signup, user signup etc all on one page we can use parts to add stuff to pages? From my last project, we ended up creating pages which had 1 column, 3 column layouts for the user to select in the NEW menu.. then they had to add the parts for everything they wanted. We ran into layout issues and I was wondering where the middle ground is, should be in order to maintain the layout that a designer has created. Even the N2 CMS demo site allows only one content 'column' which the user can add item after item to.. say the site is designed to be x columns wide (3/4 etc) some parts may be different widths, some take up two columns, some only one.. whats the best way to allow the user to have their mash-up functionality (a la facebook) but keep N2 coded the way you intended.

Thanks for any thoughts on the matter, it's just we are about to use N2 for another project and I want to make sure I don't make mistakes which we made first time round due to lack of understanding or commonly know best practices.

Cheers
Pete

Coordinator
Aug 20, 2009 at 7:50 PM

I can concur with your experience about too much layout freedom. Even the demo might be too flexible in this respect. I can reccomend providing page templates for most pages and providing parts for optional (and uncommon) content and portal pages.

Aug 21, 2009 at 2:56 PM

Is it possible to turn off zones/parts completely - or only allow them for certain pages? Also as an aside I noticed in the release notes for 1.5 that it talks about a fine grained permission model..Does this include being able to create a user which can only create pages under certain parts of the site and/or only down to a certain depth.. i.e. only create 1 level under a given 2nd level nav page?

It just feels that N2 is sometimes overpowered and acts more like a site builder rather than a CMS (which we all know that it is more), it would be nice to disable and limit a lot of it.. including stripping out parts, controlling page creation etc.

Sep 7, 2009 at 6:21 AM

Hi peteski22,

I have implemented a way of turning off the zones which may be of some assistence to you.

I modified N2.Templates.Mvc\Items\AbstractPage.cs with the following:

[EditableCheckBox("Disable Recursive Zones", 60, ContainerName = Tabs.Advanced)]
        public virtual bool DisableRecursiveZones
        {
            get { return (bool)(GetDetail("DisableRecursiveZones") ?? false); }
            set { SetDetail("DisableRecursiveZones", value, false); }
        }

        [EditableTextBox("Disable Recursive Path", 60, ContainerName = Tabs.Advanced)]
        public virtual string DisableRecursivePath
        {
            get { return (string)(GetDetail("DisableRecursivePath") ?? string.Empty); }
            set { SetDetail("DisableRecursivePath", value, string.Empty); }
        }

under the ShowTitle property and in ZoneHelper.cs:

add 2 fields:

bool _disableRecursiveZones = false;
ContentDetail drzPath = null;

and change the 2 constructors to:

public ZoneHelper(IItemContainer container, string zoneName)
            : base(container)
        {
            container.CurrentItem.Details.TryGetValue("DisableRecursivePath", out drzPath);
            if (container.CurrentItem.Details.ContainsKey("DisableRecursiveZones"))
            {
                _disableRecursiveZones = bool.Parse(container.CurrentItem.Details["DisableRecursiveZones"].Value.ToString());
            }
            ZoneName = zoneName;
        }

        public ZoneHelper(IItemContainer container, string zoneName, ContentItem item)
            : base(container, item)
        {
            //ContentDetail drzPath = null; // new ContentDetail();
            container.CurrentItem.Details.TryGetValue("DisableRecursivePath", out drzPath);
            if (container.CurrentItem.Details.ContainsKey("DisableRecursiveZones"))
            {
                _disableRecursiveZones = bool.Parse(container.CurrentItem.Details["DisableRecursiveZones"].Value.ToString());
            }
            ZoneName = zoneName;
        }

and then the ToString function to:

public override string ToString()
        {
            var partialResult = new StringBuilder();

            foreach (var child in GetItems())
            {
                ContentItem model = child;
                string partial = _templateRenderer.RenderTemplate(model, Container);

                if (!_disableRecursiveZones) // && hasRecursive)
                {
                    if (TagBuilder == null)
                    {
                        partialResult.AppendLine(partial);
                        continue;
                    }
                    TagBuilder.InnerHtml = partial;
                    partialResult.AppendLine(TagBuilder.ToString());
                }
                else
                {
                    if (drzPath != null && !child.Path.StartsWith(drzPath.ToString()))
                    {
                        continue;
                    }
                    if (TagBuilder == null)
                    {
                        partialResult.AppendLine(partial);
                        continue;
                    }
                    TagBuilder.InnerHtml = partial;
                    partialResult.AppendLine(TagBuilder.ToString());
                }
            }

            return partialResult.ToString();
        }

 

This gives the option of turning zones off below any node in  the tree with the DisableRecursiveZones checkbox. To allow display of zones below a certain level you can add the path from which to display sublevel zones with Disable Recursive Zones Path.

The mod only governs the rendering of the zone and does not interfere with the DB side at all.

Hope this helps.