1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / custom navigation template

custom navigation template

7 posts, 0 answered
  1. developer
    developer avatar
    13 posts
    Registered:
    11 Feb 2013
    01 Mar 2013
    Link to this post

    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 

    http://www.sitefinity.com/clientsfiles/303867_submenu.PNG?sfvrsn=0
           

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    01 Mar 2013 in reply to developer
    Link to this post

    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 

  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    01 Mar 2013 in reply to developer
    Link to this post

    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

  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    01 Mar 2013 in reply to Daniel Plomp
    Link to this post
    Yeah mine renders pure ul\li....so more suited to KendoUI implementation (but lightyears leaner) :)
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    01 Mar 2013 in reply to Steve
    Link to this post

    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

  6. developer
    developer avatar
    13 posts
    Registered:
    11 Feb 2013
    01 Mar 2013 in reply to Daniel Plomp
    Link to this post

    Hi Daniel,

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

  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    01 Mar 2013 in reply to developer
    Link to this post

    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

7 posts, 0 answered