Override how page title is generated

Posted by Community Admin on 04-Aug-2018 21:30

Override how page title is generated

All Replies

Posted by Community Admin on 29-Mar-2012 00:00
I would like to override how the page titles for all pages on a site are generated. The client wants the title to be similar to the site breadcrumb where it is a concatenated list of ancestral page names plus the current page.

I figure that this could be generated when a page is saved but I would have to alter the page title of the current page and all child pages. If I did it this way then if they changed their mind later then I would have to regenerate all of the page names.

Alternatively if I could just override how the page titles are put on the page then I could go get the ancestors and generate the title when the page is viewed by a user.

I lean toward the second but I don't know how to do either. Any ideas? I am also curious how the solutions will work in relation to widgets that overwrite the title of a page.

I am working on 5.X.
Posted by Community Admin on 29-Mar-2012 00:00
I definitely recommend you go the dynamic route so it does everything for you. You can use this method:

SiteMapBase.GetActualCurrentNode()

to determine the current page you're on, then traverse with the Parent property until you get to the root to build up the page title, appending it to the current page's title.

This can be done from the code-behind of the master page, or if you're not using a master page, on any regular sitefinity widget (ascx user control).

hope this is helpful!
Posted by Community Admin on 30-Mar-2012 00:00
Posted by Community Admin on 30-Mar-2012 00:00
Thanks Liam. I got it working on my codebehind for my template page last night but then I would have to implement the code on all my templates (at least the non-nested ones). The way you suggested is a lot better. Thanks!
Posted by Community Admin on 30-Mar-2012 00:00
Hi Erik,

Of course it is.

Regards
This thread is closed