Getting current page from widget - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Getting current page from widget

  • Getting current page from widget
  • I am trying to get a reference to the  Page from within a widget (it seems this should be pretty easy)

    Here is some 3.7 code that I was trying to use, without much luck.

    CmsManager man = new CmsManager(); 
    ICmsUrlContext page = (ICmsUrlContext)this.Context.Items[UrlHelper.CmsPageKey]; 
    string Id = page.PageID.ToString(); 


  • Hello Joe Keller,

    You can get the current site map node and from it get the current page:
    SiteMapNode currentNode = SiteMap.CurrentNode;
    if (currentNode != null)
        var pManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager();
        Telerik.Sitefinity.Pages.Model.PageData page = pManager.GetPageData(new Guid(currentNode.Key));

    All the best,
    Radoslav Georgiev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Would you be perhaps able to wrap this into the PageManager or Page Facade to make it easier to grab the current page reference?
  • Hi Joe,

    There is another way to get the current page - SiteMapBase.GetActualCurrentNode() will return the  PageSiteNode. We will consider adding a method in the fluent API that will return the ID directly.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Hi Radoslav,

    SiteMap.CurrentNode doesn't work in 4.1. It's returning null. In 4.1 is there an alternative way to find the current page. Simply what I need is to find the URL of the current page. The logic I have implemented was based on

    SiteMap

     

     

    .CurrentNode.Url and it's not working anymore since the CurrentNode is returning null.

    Thanks,
    Duneel

  • Hi Duneel,

    What about using GetActualCurrentNode as suggested?

    All the best,
    Ivan Dimitrov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  • Thanks Ivan! GetActualCurrentNode worked.