How to get date of published page from Navigation
Hello,
I have a piece of code where I am rendering the nodes for my left hand side navigation. Pretty standard. Now I have also been asked to, when in preview mode, to show the menu items of the pages that will be published on the same date as per the publish date of the current page in view.
Done a few attempts and haven't yet managed to do it, so coming to the forums for help.
I have the following.
protected void RTV1_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
//get the current node's URL
if (e.Node.NavigateUrl.Equals(currentNodeURL))
e.Node.Selected = true;
//ensure that the parent nodes are selected
e.Node.ExpandParentNodes();
//force the node to expand
e.Node.Expanded = true;
//if not the selected node
else
e.Node.Selected = false;
//collapse the children
e.Node.CollapseChildNodes();
//force the node property 'expanded' to false
e.Node.Expanded = false;
So for each node I want to get the page ID and get the publish date, how to achieve that?
Thanks,
R
Managed to sort it, I realised that I can actually do the following:
var provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
PageSiteNode currentNode = (PageSiteNode)provider.CurrentNode;
//and then cast the current Node to a Page Site Node
currentNode = (PageSiteNode)e.Node.DataItem;
//and then I can get the publication date of the current node
var pageManager = PageManager.GetManager();
var currentNodePublishDate = pageManager.GetPageData(currentNode.PageId).PublicationDate;
The only question now is how to get the non-published pages while rendering the control. The main point is to show to the user how the site will look when the page is published. Any thoughts anyone?
Actually best way to do it is...
var provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
PageSiteNode currentPageNode = (PageSiteNode)provider.CurrentNode;
if (currentPageNode.IsPublished())
//do something
Hello Ricardo,
As far as I underatand you'd like to check if the current page is published, and if so, execute some logic. You are right that the best way would be to use the isPublished() method. Thank you for sharing your observations with the community!
Greetings,