Append or prepend site name to page title for all pages with MVC templates

Very often it is required to add website name at the end or beginning of title for all pages in Sitefinity.

If you are using Hybrid or WebForms template, you can find solution here: https://www.sitefinitysteve.com/blog/code/2014/04/28/appending-your-domain-or-sitename-to-the-page-title

But if you are using MVC templates (Feather), you need to to follow this way:

1) In you Global asax file add event handled for Bootstrapper Initialized
2) When it was initialized subcribe to page pre render event(IPagePreRenderCompleteEvent).
3) And inside handler you can access to page properties.

Example of code:

        protected void Application_Start(object sender, EventArgs e)
        {
            Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
        }

        protected void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
        {
            if (e.CommandName == "Bootstrapped")
            {
                EventHub.Subscribe<IPagePreRenderCompleteEvent>(this.OnPagePreRenderCompleteEventHandler);
                RegisterRoutes(RouteTable.Routes);
            }
        }

        private void OnPagePreRenderCompleteEventHandler(IPagePreRenderCompleteEvent evt)
        {
            if (!evt.PageSiteNode.IsBackend)
            {
                var prefix = "Website Name ";
                evt.Page.Title = prefix + evt.Page.Title;

            }

        }




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *