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

Forums / Developing with Sitefinity / Override how page title is generated

Override how page title is generated

5 posts, 1 answered
  1. Erik
    Erik avatar
    62 posts
    Registered:
    02 May 2011
    29 Mar 2012
    Link to this post
    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.
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    29 Mar 2012
    Link to this post
    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!
  3. Liam
    Liam avatar
    15 posts
    Registered:
    29 Feb 2012
    30 Mar 2012
    Link to this post
    Answered
  4. Erik
    Erik avatar
    62 posts
    Registered:
    02 May 2011
    30 Mar 2012
    Link to this post
    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!
  5. Liam
    Liam avatar
    15 posts
    Registered:
    29 Feb 2012
    30 Mar 2012
    Link to this post
    Hi Erik,

    Of course it is.

    Regards
5 posts, 1 answered