guideline to build a navigation menu similar to sitefinity.com
Hi,
I'm wondering how to create a master page with a top horizontal navigation similar to sitefinity.com
- what kind of control should we use?
- how to bind it to the Sitemap if this is not a "navigation control"?
- how to embed links from the Sitemap into HTML layout such as the Solution Dropdown.
has anybody succeeded in replicating this nice work?
thanks
Michael
Hi Mzerbib,
For the navigation menu on www.sitefinity.com we are using a customized version of RadMenu in a Mega Drop Down application scenario. Please find attached below a small sample for the Mega menu.
Only the first level of the pages is being bound. Then each page is checked and we create a child menu item containing RadSiteMap with the child pages of the current node.The sample uses the Sitefinity API to instantiate templates and generic container from *.ascx file. Once the template in the generic container is instantiated we add the generic container as child control of a RadMenuItem.
To use the custom template, please do the following:
1) Extract the content of the archive in your project and build it.
2) Add a navigation control on the page. Choose horizontal with drop-downs and set it as in the attached image.
Hi,
Paul,
I've been told that it should work. However I was unable....
One suggestion I was given was to switch the SiteMapProvider in the itemnavigation control to a SitefinitySiteMapProvider and that got me past that error. However the SitefinitySiteMapProvider doesn't seem to like ~/ url's so I had to Page.ResolveUrl them. And it seems to work.
Still tweaking/testing though
One other thing I found was that if you have Group menu items at the top level them e.item.url will always return an empty string thus not filtering your child items. I had to cast the dataitem as a PageSiteNode and get the URL off that.
Hope that helps
Paul,
I was able to get mine up and running by tweaking the following method from the example:
void MegaMenuTemplate_IsNodeAccessible(object sender, IsAccessibleArgs e) var pageNode = e.Node as PageSiteNode; if (pageNode != null) if (!pageNode.ShowInNavigation || (!pageNode.IsGroupPage && pageNode.Hidden) || (String.IsNullOrEmpty(pageNode.Title) && // used in multilingual; captures the cases of synced, split, and group pages pageNode.Id != SiteInitializer.FrontendRootNodeId)) // ensures that the root node is not hidden and thus all other pages e.IsAccessible = false; return; //The page should be hidden if it is a group page and it has no child pages. if (pageNode.IsGroupPage && pageNode.ChildNodes.Count < 1) e.IsAccessible = false; return; else throw new NotSupportedException("The supported types are 'TaxonSiteNode' or 'PageSiteNode'."); e.IsAccessible = true; I am using Sitefinity 5 and I just tried this using Boyan's instructions:
1) Extract the content of the archive in your project and build it.
2) Add a navigation control on the page. Choose horizontal with drop-downs and set it as in the attached image.
I don't get the ~/home error. I get a different error about object reference not set to instance of an object.
Here is the error info.
Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] Telerik.Web.UI.ControlItem.PopulateFromDataItem(PropertyDescriptorCache properties, Object dataItem, String dataMember, Int32 depth) +332 Telerik.Web.UI.NavigationItem.PopulateFromDataItem(PropertyDescriptorCache properties, Object dataItem, String dataMember, Int32 depth) +55 Telerik.Web.UI.RadSiteMapNode.PopulateFromDataItem(PropertyDescriptorCache properties, Object dataItem, String dataMember, Int32 depth) +30 Telerik.Web.UI.ControlDataBinder.BindItem(IList items, Object dataObject, Object dataItem, String dataMember, Int32 depth) +111 Telerik.Web.UI.ControlDataBinder.BindToEnumerableData(IEnumerable dataSource) +136 Telerik.Web.UI.ControlDataBinder.BindToEnumerableData(IEnumerable data, String dataFieldID, String dataFieldParentID) +112 Telerik.Web.UI.HierarchicalControlItemContainer.PerformDataBinding(IEnumerable data) +662 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +170 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +267 Telerik.Sitefinity.Web.UI.NavigationControls.Breadcrumb.Breadcrumb.OnPreRender(EventArgs e) +40 System.Web.UI.Control.PreRenderRecursiveInternal() +154 System.Web.UI.Control.PreRenderRecursiveInternal() +239 System.Web.UI.Control.PreRenderRecursiveInternal() +239 System.Web.UI.Control.PreRenderRecursiveInternal() +239 System.Web.UI.Control.PreRenderRecursiveInternal() +239 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3913Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272You didn't mention the Template location, so on the offchance...
MegaMenuTemplate.ascx.cs contains an explicit path reference the item (drop-down) template, which should be adapted to your site.
TemplatePath = "~/ControlTemplates/ItemTemplate.ascx",
I am using the same structure. The template lives at "~/ControlTemplates/ItemTemplate.ascx". I did notice that the ItemTemplate file that I downloaded in the zip file only contains 3 lines of code.
<%@ Control Language="C#" AutoEventWireup="true" %><telerik:RadSiteMap runat="server" ID="RadSiteMap1" DataSourceID="siteMapDataSource1"></telerik:RadSiteMap><asp:SiteMapDataSource runat="server" ID="siteMapDataSource1" />That's correct - this application of the mega-menu modifies the item template at run-time. I actually modified this behaviour to suit my own needs, which was to have a fixed-layout dropdown for some sections, and standard dropdowns for other sections, but it depends on your site's needs.
I guess the obvious step in your case would be to to run it from VS and break-point it at the ItemDataBound event (triggered by the level-1 items) and then step through it to find the missing object reference.