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

Forums / Developing with Sitefinity / How to get date of published page from Navigation

How to get date of published page from Navigation

4 posts, 0 answered
  1. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    20 Mar 2013
    Link to this post
    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
            
  2. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    20 Mar 2013 in reply to Ricardo
    Link to this post
    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?
  3. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    03 Apr 2013
    Link to this post
    Actually best way to do it is...

     var provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
                        PageSiteNode currentPageNode = (PageSiteNode)provider.CurrentNode;

                        if (currentPageNode.IsPublished())
    {
    //do something
    }
  4. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    08 Apr 2013
    Link to this post
    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,
    Jen Peleva
    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
4 posts, 0 answered