SitefinitySiteMapDataSource - How to control Top menu items and Sitemap items separately
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
Hi Nancy,
Thank you for contacting support.
Try replacing <navcontrols:SitefinitySiteMapDataSource with
<
asp:SiteMapDataSource
ID
=
"SiteMapDataSource1"
runat
=
"server"
ShowStartingNode
=
"false"
StartFromCurrentNode
=
"false"
/>
Yes, I was using <asp:SiteMapDataSource /> before and it was showing all the nodes including those in "draft mode" which is not right.
Thanks
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
;
Thanks Craig. I will try your code shortly.