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

Forums / General Discussions / Submenu navigation 2 levels

Submenu navigation 2 levels

12 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    03 Oct 2011
    Link to this post
    Hi all,

    I need to have a submenu inside a template that can show navigation items 2 levels deep.
    See the attachment for an example.

    Someone who did already managed to do this?

    I've looked at the navigation control, but none of the options seems to fit for this.
    I can create a custom control for this, but maybe it is possible in another way.

    Regards,
    Daniel
  2. Richard
    Richard avatar
    63 posts
    Registered:
    20 Jan 2010
    03 Oct 2011
    Link to this post
    Hi,

    I would also be interested in knowing how to do this as v3.7 did this but not v4?

    thanks
  3. Nicolas
    Nicolas avatar
    156 posts
    Registered:
    19 Jan 2011
    03 Oct 2011
    Link to this post
    Hi,

    I made a custom control for this.

    Regards,
    Nicolas
  4. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    03 Oct 2011
    Link to this post
    Awesome! Would you like to share it? 

    Cheers,
    Daniel
  5. Nicolas
    Nicolas avatar
    156 posts
    Registered:
    19 Jan 2011
    03 Oct 2011
    Link to this post
    No problem :)

    VerticalMenu.acsx :
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VerticalMenu.ascx.cs" Inherits="SitefinityWebApp.CustomComponent.VerticalMenu" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
     
    <sf:ResourceLinks ID="resourceLinks" runat="server" UseEmbeddedThemes="false">
         <sf:ResourceFile Name="~/Styles/VerticalMenu.css" Static="true" />
    </sf:ResourceLinks>
     
    <div id="verticalMenu">
        <asp:Literal ID="menuContent" runat="server" />
    </div>

    VerticalMenu.cs :
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using SF.Widgets.CommonLib;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Web;
    using System.Globalization;
    using System.Threading;
     
    namespace SitefinityWebApp.CustomComponent
    {
        public partial class VerticalMenu : System.Web.UI.UserControl
        {
            #region Properties
     
            protected PageNode currentNode;
            protected IList<PageNode> NodeList;
            protected List<PageNode> ParentNodes = new List<PageNode>();
     
            #endregion Properties
     
            #region Methods
     
            private PageNode GetParent(PageNode pNode)
            {
                PageNode pToReturn = pNode;
                ParentNodes.Add(pToReturn);
     
                if (pNode != null)
                {
                    if (pNode.Parent != pNode.RootNode)
                        pToReturn = this.GetParent(pNode.Parent);
                }
     
                return pToReturn;
            }
     
            private void GetCurrentPage()
            {
                //Get current page Key
                if (!string.IsNullOrEmpty(SiteMapBase.GetCurrentProvider().CurrentNode.Key))
                {
                    Guid currentKey = new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key);
                    PageManager pMng = new PageManager();
     
                    currentNode = pMng.GetPageNode(currentKey);
                    NodeList = this.GetParent(currentNode).Nodes;
                }
            }
     
            private void DisplayNode(IList<PageNode> pNodes, StringBuilder sb, bool firstLevel)
            {
                sb.Append("<ul>");
                CultureInfo language = Thread.CurrentThread.CurrentCulture;
                 
                foreach (PageNode pNode in pNodes)
                {               
                    if (pNode.ApprovalWorkflowState == "Draft"
                        || !pNode.AvailableCultures.Contains(language)
                        || (pNode.NodeType == NodeType.Group && pNode.Nodes.Count == 0))
                        continue;
     
                    if (pNode.WasPublished && pNode.ShowInNavigation)
                    {
                        if (!firstLevel && !ParentNodes.Contains(pNode.Parent))
                        {
                            continue;
                        }
     
                        if (this.IsSelected(pNode.Id))
                        {
                            sb.Append("<li class=\"selected\">");
                        }
                        else
                        {
                            sb.Append("<li>");
                        }
     
                        sb.AppendFormat("<a href=\"{0}\">{1}</a>", pNode.GetFullUrl(language, false).Trim('~'), pNode.Title);
     
                        if (pNode.Nodes.Count > 0)
                            this.DisplayNode(pNode.Nodes, sb, false);
     
                        sb.Append("</li>");
                    }
                }
     
                sb.Append("</ul>");
            }
     
            private bool IsSelected(Guid IdNode)
            {
                foreach (PageNode pN in ParentNodes)
                {
                    if (pN.Id.Equals(IdNode))
                        return true;
                }
                return false;
            }
     
            #endregion Methods
     
            protected void Page_Load(object sender, EventArgs e)
            {
                if (SystemManager.IsDesignMode && !SystemManager.IsPreviewMode)
                {
                    return;
                }
     
                GetCurrentPage();
     
                StringBuilder sb = new StringBuilder();
                this.DisplayNode(NodeList, sb, true);
     
                this.menuContent.Text = sb.ToString();
            }
        }
    }

    You just have to change the css file in ascx.

    Regards,
    Nicolas
  6. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    13 Oct 2011
    Link to this post
    Hi Nicolas,

    Thanks for sharing.
    I'm having some troubles with getting only the languages that are for the current selected culture. How would you adjust the code so that the menu shows only the current selected language?

    When I have a site with multiple languages it now shows all languages beneath each other.

    Regards,
    Daniel
  7. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    13 Oct 2011
    Link to this post
    Dear Daniel

    I usualy do this

    1. Level standard SF navigation widget

    2. and 3. level I use the DataSitemap and a RadPanelbar

    Maybe the screenshots help you set it up.

    Step 1
    Enable RadControls (screenshot 1). This will make them visible in your toolbox

    Step 2
    Drag a Site map data source widget to your template (screenshot 2)

    Step 3
    Configure the site map data source (screenshot 3)
    Copy the ID to past it later to the pannel bar

    Step 4
    Drag a PanelBar to the template (screenshot 4)

    Step 5
    Configure the PanelBar (screenshot 5)

    Hope I did not miss something here.

    Give it a try.

    Markus

  8. Nicolas
    Nicolas avatar
    156 posts
    Registered:
    19 Jan 2011
    13 Oct 2011
    Link to this post
    Hi,

    Weird i'm also in multilingual and it works for me. Your page are synchronised ?

    I use into DisplayNode : CultureInfo language = Thread.CurrentThread.CurrentCulture;


    Regards,
    Nicolas
  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    13 Oct 2011
    Link to this post
    Okay, strange. I'm not sure if it synchronized. I'll check.
    See the screenshot for the behaviour. I enabled two languages at the moment.
  10. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    13 Oct 2011
    Link to this post
    @Markus: hey, your solutions works okay, so because of time I'll go for this. Although the RadPanelBar creates lots over overhead. I'm more into a clean solution, but don't have time to figure it out. Thanks!
  11. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    13 Oct 2011
    Link to this post
    Dear Daniel

    Glad to hear it works :-)

    Markus
  12. Sweta
    Sweta avatar
    2 posts
    Registered:
    05 Mar 2015
    09 Feb
    Link to this post

    Hi Markus,

    It works well when project is deployed on root. Navigation links are not found when project is deployed inside a folder. It does not takes its path. Can you please help.

12 posts, 0 answered