SitefinitySiteMapDataSource - How to control Top menu items

Posted by Community Admin on 04-Aug-2018 13:58

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

All Replies

Posted by Community Admin on 16-Jan-2013 00:00

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
 

Posted by Community Admin on 19-Jan-2013 00:00

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

Posted by Community Admin on 21-Jan-2013 00:00

Yes, I was using <asp:SiteMapDataSource /> before and it was showing all the nodes including those in "draft mode" which is not right.

Thanks

Posted by Community Admin on 24-Jan-2013 00:00

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

Posted by Community Admin on 24-Jan-2013 00:00

Thanks Craig. I will try your code shortly.

This thread is closed