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

Forums / General Discussions / PageManager to change page titles?

PageManager to change page titles?

9 posts, 1 answered
  1. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    08 Jul 2011
    Link to this post
    Hey all,

    Our client has set all of their pages to very basic titles, such as Home, About us, etc. They want to change all of the pages (250+) that they have to include their business name, followed by what they already have, such as "Acme Corp | Home."

    I'm attempting to work with the pageManager calls right now to do so, but am having no such luck. Current code is below that I assumed would do the trick for a single page for testing.

    var pageManager = PageManager.GetManager();
    var page = pageManager.GetPageNodes().Where(p => p.Title == "changetitles").SingleOrDefault();
    page.Title = "Acme Corp | " + page.Title;   
    pageManager.SaveChanges();

    Thanks!

  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    09 Jul 2011
    Link to this post
    Hello Brad,

    Please find below a code sample that does this exact functionality for all frontend pages.
    var fluent = App.WorkWith().Pages();
    var mypage = fluent.LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                             .Where(p => p.Page != null)
                             .ForEach(p => p.Page.Title =  "Telerik | "+ p.Page.Title)
                              .SaveChanges();


    All the best,
    Boyan Barnev
    the Telerik team
    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
  3. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    11 Jul 2011
    Link to this post
    Boyan,

    Thank you - I changed your code just slightly to modify only the HtmlTitle attribute, rather than the title attribute (since we use that for the navigation links).

    var fluent = App.WorkWith().Pages();
            var mypage = fluent.LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
            .Where(p => p.Page != null)
            .ForEach(p => p.Page.HtmlTitle = "Acme Corp - " + p.Page.HtmlTitle)
            .SaveChanges();

    The only issue we're running in to is that sometimes it throws an error such as the following:

    Telerik.Sitefinity.Security.SecurityDemandFailException: You are not allowed to modify this page: Contact Us

    Which stops the whole loop and nothing saves. Is this just a permission issue, or some random problem with the page itself? It is not locked by anyone at the time of running the snippet.

    Thanks again!
  4. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    13 Jul 2011
    Link to this post
    Hello Brad,

    It looks like a permissions issue to me, can you, please make sure you are running the code when logged in with an administrator account when running the code?

    Best wishes,
    Boyan Barnev
    the Telerik team
    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
    Answered
  5. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    13 Jul 2011
    Link to this post
    Boyan,

    Tried and tried again when I made sure I was logged in as administrator - I happened to have the page open (the page with our Change Titles code on it), so I closed it, re-published, logged out, logged back in and that seemed to do the trick - all of the page titles now have what the code was supposed to do.

    I don't know if something was being stuck in the cache system or what was going on, but as soon as I re-published and logged back in, we've had 0 issues with changing the titles multiple times, and changing other attributes like the description as well.

    Thanks!
  6. Brad
    Brad avatar
    28 posts
    Registered:
    20 Sep 2010
    13 Jul 2011
    Link to this post
    An update to the code above.

    Using the pipe character, "|" in your page titles/HTML Titles like the code above changes, will not allow you to save the page within Sitefinity once you run this snippet because the pipe is considered an illegal character. You can change the pipe to a hyphen and everything will run correctly, as well as you will be able to save the page's Title/Properties with the hyphen.
  7. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    14 Jul 2011
    Link to this post
    Hello Brad,

    Actually the code was running fine on my side, can you please check the regular expression for allowed characters int he page title, and if necessary add the pipe symbol as allowed. The problem might be coming from the fact that we are using the page title to for the HtmlTitle as well (used for SEO purposes) so you might want to check this regex as well. Please find attached a screenshot demonstrating the location for this setting in Sitefinity backend -> administration -> Settings-> Advanced.

    Regards,
    Boyan Barnev
    the Telerik team
    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
  8. Ankit
    Ankit avatar
    13 posts
    Registered:
    29 Jul 2011
    19 Aug 2011
    Link to this post
    Hello Everyone,
    I have the same Problem , i want to change the Page title according to the user Logged in . The Page Title will be   'Company Name' - Home etc and Company Name I am retriving from another database . Please send me neccessary code regarding this. 


     Thanks
    Ankit Rastogi
  9. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    19 Aug 2011
    Link to this post
    Hi Ankit,

    Can you please let us know where do you expect to see the dynamic page titles according to the logged in user - on the frontend or in the site's bakcend. Please have in mind that changing the Title property of a page would not be a plausible solution if your site has several concurrent users, and also this is not advisable performance-wise. What I'd suggest you, since I guess you'd like to implement this solution on the frontend, is to create a custom navigation, and bind it to our SitefinitySiteMapDataSource control. You'll be displaying all pages as they are arranged in the sitemap, but you can customize the way page titles are rendered according to the desired functionality.

    Kind regards,
    Boyan Barnev
    the Telerik team
    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
9 posts, 1 answered