custom navigation template

Posted by Community Admin on 04-Aug-2018 14:23

custom navigation template

All Replies

Posted by Community Admin on 01-Mar-2013 00:00

Hi all,

I want to write custom navigation. I don't want to show 'Show in navigation' flag value false. I've a site map like this.

 |__A
 |   |__B (Show in navigation flag is false)
 |   |__C
 |          |__D         
 |__E
 |__F
       |__G

aspx

 <sf:ConditionalTemplate ID="ConditionalTemplate8" Left="NavigationMode" Operator="Equal"

            Right="VerticalTree" runat="server">
            <navcontrols:SiteMapNavigationTreeView runat="server" ID="siteMapControl_verticaltree"
                Skin="Sitefinity">
            </navcontrols:SiteMapNavigationTreeView>
        </sf:ConditionalTemplate>

protected void Page_Load(object sender, EventArgs e)
    
        SiteMapNode smn = SiteMapBase.GetCurrentProvider().CurrentNode;

        while (smn.ParentNode != null)
       
            if (smn.ParentNode.ParentNode == SiteMap.RootNode)
           
                smn.ParentNode.ChildNodes.RemoveAt(1);
                siteMapControl_verticaltree.DataSource = getNodes(smn);
                siteMapControl_verticaltree.DataBind();               
                break;
           

            smn = smn.ParentNode;
       
   

    protected SiteMapNodeCollection getNodes(SiteMapNode smn)
   
        SiteMapNodeCollection col = new SiteMapNodeCollection();

        for (int i = 0; i < smn.ParentNode.ChildNodes.Count; i++)
       
            if (((Telerik.Sitefinity.Web.PageSiteNode)(smn.ParentNode.ChildNodes[i])).ShowInNavigation)
           
                col.Add(smn.ParentNode.ChildNodes[i]);
           
       
        return col;
   

It doesn't work correctly. Page 'B' still show in my navigation. How to solve this problem? Can you give me sample C# code?

Certainly I want to do something like this and want to set Show In Navigation flag 

www.sitefinity.com/.../303867_submenu.PNG
       

Posted by Community Admin on 01-Mar-2013 00:00

I've attached my *simple* vertical menu if you want to try that...it's got <i> tags in the generated markup for font-awesome, you can blow those away, and the template is wrapped in a fake layout control, that can be killed too if you want.

 https://dl.dropbox.com/u/3234184/VerticalMenu.zip 

Posted by Community Admin on 01-Mar-2013 00:00

Hey Developer,

Funny, I've built the EndExclusion website (in your screenshot) last year. It however uses a much simpler approach. Just a RadPanelBar together with the SitefinitySitemapDatasource. I'll give you some code, maybe it works for your case also:

Subnavigation.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SubNavigation.ascx.cs" Inherits="SitefinityWebApp.Widgets.Navigation.SubNavigation.SubNavigation" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
    TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls"
    TagPrefix="sfNav" %>
<telerik:RadPanelBar ID="sideNavigation" runat="server" EnableEmbeddedBaseStylesheet="false"
    EnableEmbeddedSkins="false" DataSourceID="sfDatasource" Skin="Custom">
</telerik:RadPanelBar>
<sfNav:SitefinitySiteMapDataSource ID="sfDatasource" runat="server" SiteMapProvider="SitefinitySiteMap"
    ShowStartingNode="true" StartFromCurrentNode="false" StartingNodeOffset="1" />

 

SubNavigation.cs

protected void Page_Load(object sender, EventArgs e) this.sideNavigation.ItemDataBound += new Telerik.Web.UI.RadPanelBarEventHandler(sideNavigation_ItemDataBound);
 
        void sideNavigation_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)
            if (this.GetIndexRenderMode() == IndexRenderModes.Normal)
                var item = e.Item.DataItem as PageSiteNode;
                var actualCurrentNode = SiteMapBase.GetActualCurrentNode();
                if (actualCurrentNode.LocalizationStrategy == Telerik.Sitefinity.Localization.LocalizationStrategy.Split)
                    if (actualCurrentNode.PageLinksIds != null)
                        if (actualCurrentNode.PageLinksIds.Contains(item.Id))
                            e.Item.Selected = true;
                 else
                    if (item.Url == actualCurrentNode.Url)
                        e.Item.Selected = true;
                
            
        

 

The SitefinitySiteMapDataSource takes care of all the Page properties like 'Visible' etc. and also multilingual functionality.

Kind regards,
Daniel

Posted by Community Admin on 01-Mar-2013 00:00

Yeah mine renders pure ul\li....so more suited to KendoUI implementation (but lightyears leaner) :)

Posted by Community Admin on 01-Mar-2013 00:00

Ah! :) We posted at the same time. I didn't saw the previous post and was wondering why you didn't give the guy an example then ;) LOL.

I agree it is definitely more clean!

Kind regards,
Daniel

Posted by Community Admin on 01-Mar-2013 00:00

Hi Daniel,

Thanks for your reply. Can you also post 'GetIndexRenderModepost' method code?

Posted by Community Admin on 01-Mar-2013 00:00

Hi Developer,

Just make sure you have these usings inside your code-behind:

using System;
using System.Web.UI;
using Telerik.Sitefinity.Web;
using Telerik.Sitefinity.Web.UI;

Kind regards,
Daniel

This thread is closed