Retrieve Page Title and Page URL from a widget

Posted by Community Admin on 04-Aug-2018 20:57

Retrieve Page Title and Page URL from a widget

All Replies

Posted by Community Admin on 05-Dec-2013 00:00

We need to create social sharing link urls in a widget:

For instance something like this:

twitter.com/share

How do we get this widget to pull in the current pages URL and PAGETITLE of the page its been dropped onto? Id rather do this automatically vs having a content editor enter in the page URL and Page Title each time they drop the widget on a page.

Posted by Community Admin on 10-Dec-2013 00:00

Hi,

You can try with the following code:

var manager = PageManager.GetManager();
           var node = SiteMapBase.GetActualCurrentNode();           
var title = node.Title;
var url = node.Url

I hope this helps.

Regards,
Pavel Benov
Telerik
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

Posted by Community Admin on 10-Dec-2013 00:00

Excellent thanks Pavel,

Quick question: what is manager used for? i don't see it referenced anywhere else in the code you posted.

Posted by Community Admin on 11-Dec-2013 00:00

Hi,

For the specifics of the PageManager class you can take a look at the following documentation article:

http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/pages

As a whole managers in Sitefinity are the connection between your custom implementation and our Providers that associate with different data in the database. The managers in Sitefinity (there are different for each content type - NewsManager, EventsManager etc.) are basically classes that expose to the developers means to do CRUD operations with the system. You can take a look also at the Provider model that Sitefinity uses.

Regards,
Pavel Benov
Telerik

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

Posted by Community Admin on 14-Dec-2013 00:00

Couple of notes:
1) In Pavel's code, he didn't need the PageManager, so you can drop that if you prefer
2) I would prefer to use e.g., Page.Request.Url.AbsoluteUri instead of node.Url - handles querystring etc

Posted by Community Admin on 14-Dec-2013 00:00

Thinking about it you should use Page.Title instead of node.Title because:
Some widgets in Sitefinity replace the Page.Title (e.g., on a News Item page)

Be careful though, because this Title replacement is done after the Page_Load event for your UserControl

I would suggest interrogating Page.Title during the Page_PreRender event, so your control would be something like (I just wrote this from my head, but be aware of the URL encoding I guess is important)...

Page_PreRender(object sender, EventArgs e)
  myLink.NavigateUrl = HttpServerUtility.UrlEncode(string.Format("twitter.com/share, Page.Request.Url.AbsoluteUri, Page.Title));

Posted by Community Admin on 14-Dec-2013 00:00

Thanks Stephen,

Can this be put right into a master template as well? For instance to populate Facebook open graph meta tags?

Kele.

Posted by Community Admin on 14-Dec-2013 00:00

Yep no problem with that, either as a Widget/UserControl on a Template, or on a Master Page that is imported as a Template.

Posted by Community Admin on 01-Jul-2017 00:00

Using below query you will get all the page url now its up to you how do we place this code in our code.

SELECT sf_page_node.Title_,
  _url_parent =
    CASE WHEN (sf_page_node_2.url_name_ = N'Pages')   THEN '/'
        ELSE sf_page_node_2.url_name_ +'/'
    END,
  sf_page_node.url_name_ AS url_page
FROM
  sf_page_node LEFT OUTER JOIN
  sf_page_node AS sf_page_node_2
  ON sf_page_node.parent_id = sf_page_node_2.id
WHERE (sf_page_node.root_id =
    (
      SELECT id FROM sf_page_node AS sf_page_node_1 WHERE (nme = 'FrontendSiteMap')
     )
   ) AND
  (sf_page_node.show_in_navigation = 1) AND
  (sf_page_node.render_as_link = 1) AND
  (sf_page_node.node_type = 0) AND
  (sf_page_node.approval_workflow_state_ = N'Published')

This thread is closed