Zone path suggestion

Topics: Developer Forum
Jan 5, 2007 at 8:54 PM
One this that I miss (and may very well just have missed, please point me in the right direction then :)) with the zone path feature is the ability to select a zone from the first parent page that has a zone added, somthing that works more like the dynamic properties in EPiServer.
Here is my way of implementing this feature,
---------- N2.Web.UI.WebControls.Zone.cs ----------

public virtual ContentItem CurrentItem
{
get
{
if (currentItem == null)
{
this.currentItem = ItemUtility.FindCurrentItem(this.Parent);
if (this.Path.Length > 0)
{
this.currentItem = ItemUtility.WalkPath(currentItem, Path, ZoneName);
}
}
return currentItem;
}
}

---------------------------------------------------
Call the new function WalkPath with 3 parameters, the last one takes the zone name.
------------ N2.Web.UI.ItemUtility.cs -------------

internal static ContentItem WalkPath(ContentItem startItem, string path)
{
return WalkPath(startItem, path, string.Empty);
}

internal static ContentItem WalkPath(ContentItem startItem, string path, string zoneName)
...
else if ((name == "...")&&(!string.IsNullOrEmpty(zoneName)))
{
bool exit=false;
do
{
item = item.Parent;
foreach (ContentItem ci in item.Children)
{
if (string.Compare(zoneName, ci.ZoneName, true) == 0)
{
exit = true;
break;
}
}
} while ((item.Parent != null) && (exit == false));
}

---------------------------------------------------
Add the new function with 3 parameters the and a new else statement that moves up the page tree looking for a parent with the zone we are looking for, when it's found we return that page. Loop until we are at the root or have found a parent with the zone.

/Viktor
Coordinator
Jan 6, 2007 at 11:02 AM
If I understand you correctly the purpose would be adding dynamic parts (user controls) on one level in the hierarchy, and then have them appear on all sub-levels? For this you are suggesting an extension to the path syntax. Where "..." would mean: find the first parent item with items in the specified zone.

Interesting. I've been thinking of making the syntax xpath:esque although I'm not sure it would solve the recursive part of the problem.

I like your solution. The extension point I had in mind for the kind of functionality above was inheriting the zone control and override either CurrentItem (to provide a suitable parent item) or DataSource (to provide a customized set of data items).

Thank you
/Crisitan
Jan 6, 2007 at 4:00 PM
Exactly, but insted of it always being there with this code you still have to select it (e.g. select the "..." path from the zone path drop down list) for every page you want it on.

/Viktor