More in this section

Forums / Developing with Sitefinity / SitefinitySiteMapDataSource - How to control Top menu items and Sitemap items separately

SitefinitySiteMapDataSource - How to control Top menu items and Sitemap items separately

5 posts, 0 answered
  1. Nancy
    Nancy avatar
    3 posts
    Registered:
    16 Jan 2013
    16 Jan 2013
    Link to this post

    I am using the following controls in the Sitemap:

    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="navcontrols" %>

    <navcontrols:SitefinitySiteMapDataSource ID="SiteMapDataSource1" StartingNodeUrl="/home" runat="server" ShowStartingNode="false" />
    <telerik:RadSiteMap ID="RadSiteMap1" DataSourceID="SiteMapDataSource1" runat="server"></telerik:RadSiteMap>

     I am also using the same <navcontrols /> for the top menu.

    The scenario is the editors will control which top menu items to show or not by checking the "Show in navigation" option in the CMS. However the Sitemap must show the published pages (not the draft pages) which have "Show in navigation" unchecked in the CMS.

    Can you show me how I can achieve this?

     Thanks
     

  2. Craig Iredale
    Craig Iredale avatar
    0 posts
    Registered:
    20 Jan 2015
    19 Jan 2013
    Link to this post
    Hi Nancy,

    Thank you for contacting support.

    Try replacing <navcontrols:SitefinitySiteMapDataSource with

    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" StartFromCurrentNode="false" />

    This will display pages which have "Show in navigation" unchecked in the CMS.

    Greetings,
    Craig Iredale
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Nancy
    Nancy avatar
    3 posts
    Registered:
    16 Jan 2013
    21 Jan 2013
    Link to this post
    Yes, I was using <asp:SiteMapDataSource /> before and it was showing all the nodes including those in "draft mode" which is not right.

    Thanks
  4. Craig Iredale
    Craig Iredale avatar
    0 posts
    Registered:
    20 Jan 2015
    24 Jan 2013
    Link to this post
    Hello Nancy,

    The following code sample will do what you want. It will display all the published pages of the site but not pages that are unpublished or are in draft mode. Additionally, it will display pages regardless of whether "show in navigation" is checked or unchecked in the CMS.

    protected void Page_Load(object sender, EventArgs e)
    {
        RadSiteMap1.NodeDataBound += RadSiteMap1_NodeDataBound;
        SiteMapDataSource smds = new SiteMapDataSource();
        smds.ShowStartingNode = false;
        RadSiteMap1.DataSource = smds;
        RadSiteMap1.DataBind();
    }
     
    void RadSiteMap1_NodeDataBound(object sender, RadSiteMapNodeEventArgs e)
    {
        RadSiteMapNode node = e.Node;
     
        string navigationUrl = node.NavigateUrl;
     
        PageManager pageManager = PageManager.GetManager();
     
        using (new ElevatedModeRegion(pageManager))
        {
            var pageNodes = pageManager.GetPageNodes().ToList();
            PageNode pageNodePublished = pageNodes.Where(pn => pn.GetFullUrl() == navigationUrl && pn.Page.Status == ContentLifecycleStatus.Live).FirstOrDefault();
            if (pageNodePublished == null)
            {
                node.Visible = false;
            }
        }
    }


    Regards,
    Craig Iredale
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Nancy
    Nancy avatar
    3 posts
    Registered:
    16 Jan 2013
    24 Jan 2013 in reply to Craig Iredale
    Link to this post
    Thanks Craig. I will try your code shortly.
5 posts, 0 answered