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

Forums / Sitefinity SDK / Getting current page from widget

Getting current page from widget

7 posts, 1 answered
  1. Joe Keller
    Joe Keller avatar
    48 posts
    Registered:
    07 Apr 2010
    08 Sep 2010
    Link to this post
    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(); 


  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Sep 2010
    Link to this post
    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.
    Answered
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    23 Dec 2010
    Link to this post
    Would you be perhaps able to wrap this into the PageManager or Page Facade to make it easier to grab the current page reference?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Dec 2010
    Link to this post
    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.
  5. Duneel
    Duneel avatar
    166 posts
    Registered:
    08 Dec 2010
    29 Apr 2011
    Link to this post
    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

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    03 May 2011
    Link to this post
    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 >>

  7. Duneel
    Duneel avatar
    166 posts
    Registered:
    08 Dec 2010
    03 May 2011
    Link to this post
    Thanks Ivan! GetActualCurrentNode worked.
7 posts, 1 answered