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)
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));
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
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
Thanks Ivan! GetActualCurrentNode worked.