Manipulating Page Titles In Sitefinity
While Sitefinity makes lots of things easy, sometimes the simplest tasks take a lot more knowledge of Sitefinity’s internal workings than you’d imagine. This post investigates what options for controlling page titles come out of the box in Sitefinity 5, and what it takes to accomplish some more complicated page title requirements.
Controlling Page Title from a Page
Like practically any CMS system, Sitefinity gives content creators the ability to set the title of any page through backend editing tools. Once set, the page’s title is rendered as it should in the markup as a TITLE element within the document’s HEAD element.

Controlling Page Title from a Control
Sitefinity offers options from within many of the built-in widgets for controlling the title of a page. For example, if you edit the NewsView widget, you can determine how the Page’s title will be affected when a single item view is rendered. Edit the control settings and click Advanced. You’ll find a text property called “PageTitleMode.”
There are three values you can enter here that will control how page titles are handled on a single item view:
- Replace When you view the detail page, the page title is replaced with the item title.
- Append When you view the detail page, the item title is appended (with a space character) to the page title.
- DoNotSet When you view the detail page, the page title is unaltered.

Controlling Page Title Globally
What if you want to edit page titles for every page in the site? For example, suppose you wanted your company name prepended to every page in the entire site. One rather unwieldy way to accomplish this would be to edit every existing page to meet your formatting requirements, and require that any future pages follow these guidelines. Another approach is to override Sitefinity’s page resolver class and dynamically modify the title of every page that Sitefinity serves. While this is a very simple process that I’ve seen mentioned in several forum posts, I’ve yet to see an actual explanation of how this is done. It requires two steps:
- Create a class that inherits from the Telerik.Sitefinity.Abstractions.VirtualPath.SitefinityPageResolver class.
- Register your page resolver during Sitefinity’s bootstrap phase from within the global.asax file.
Creating the Page Resolver Class
For my purposes I’ve created a class library called Copious.Sitefinity.Utilties, which I’ve added to a Sitefinity solution and referenced. If you do the same, you’ll need to reference the appropriate Telerik DLLs in your library:
- Telerik.OpenAccess
- Telerik.Sitefinity
- Telerik.Sitefinity.Model
- Telerik.Sitefinity.Utilities
With that taken care of, The first thing to do is create a page resolver class class and bring in the correct using statements:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Sitefinity.Abstractions.VirtualPath;
using System.Collections.Specialized;
using System.Collections;
using Telerik.Sitefinity.Configuration;
namespace Copious.Sitefinity.Utilities {
public class FlexiblePageResolver : SitefinityPageResolver {
…
}
}
Now, override the SetPageDirectives Method:
/// <summary>
/// Overrides setting the page directives and allows you to set the Title of the page through Sitefinity's advanced configuration
/// </summary>
///<param name="pageData" />
///<param name="directives" />
protected override void SetPageDirectives(Telerik.Sitefinity.Pages.Model.PageData pageData, DirectiveCollection directives) {
string siteName = "My Site";
string pageTitleFormat = "{0} | {1}";
var pageAttribs = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
pageAttribs["Language"] = "C#";
this.AddPageDirectiveValue(pageAttribs, "EnableViewState", pageData.EnableViewState, true);
this.AddPageDirectiveValue(pageAttribs, "EnableViewStateMac", pageData.EnableViewStateMac, true);
this.AddPageDirectiveValue(pageAttribs, "ViewStateEncryptionMode", pageData.ViewStateEncryption, System.Web.UI.ViewStateEncryptionMode.Auto);
this.AddPageDirectiveValue(pageAttribs, "MaintainScrollPositionOnPostback", pageData.MaintainScrollPositionOnPostback, false);
this.AddPageDirectiveValue(pageAttribs, "Trace", pageData.Trace, false);
this.AddPageDirectiveValue(pageAttribs, "TraceMode", pageData.TraceMode, System.Web.TraceMode.SortByTime);
this.AddPageDirectiveValue(pageAttribs, "ErrorPage", pageData.ErrorPage);
this.AddPageDirectiveValue(pageAttribs, "EnableTheming", pageData.EnableTheming, true);
this.AddPageDirectiveValue(pageAttribs, "EnableEventValidation", pageData.EnableEventValidation, true);
this.AddPageDirectiveValue(pageAttribs, "EnableSessionState", pageData.EnableSessionState, true);
this.AddPageDirectiveValue(pageAttribs, "ResponseEncoding", pageData.ResponseEncoding);
this.AddPageDirectiveValue(pageAttribs, "ValidateRequest", pageData.ValidateRequest, true);
this.AddPageDirectiveValue(pageAttribs, "Title", string.Format(pageTitleFormat, pageData.HtmlTitle, siteName));
this.AddPageDirectiveValue(pageAttribs, "MasterPageFile", pageData.MasterPage);
this.AddPageDirectiveValue(pageAttribs, "MetaDescription", pageData.Description);
this.AddPageDirectiveValue(pageAttribs, "MetaKeywords", pageData.Keywords);
this.AddPageDirectiveValue(pageAttribs, "Buffer", pageData.BufferOutput, true);
this.AddPageDirectiveValue(pageAttribs, "Inherits", pageData.CodeBehindType);
directives.Add(new Directive("Page", pageAttribs));
}
As you can see, the SetPageDirective method provides an opportunity to set any page attribute we want. There are a lot of things you could do here, including programmatically setting metadata or whether view state is enabled. All we need to do is alter the title to display the name of our website in front of the page’s title that gets set in the backend. Now, to make our method get called when Sitefinity renders pages:
- If you don’t have a global.asax file, use Visual Studio to create one, and make sure it has the following using statements:
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Abstractions.VirtualPath;
using Telerik.Microsoft.Practices.Unity;
- During the Application_Start phase, add a new event handler for Bootstrapper.Initialized:
protected void Application_Start(object sender, EventArgs e){
Bootstrapper.Initialized += new EventHandler(Bootstrapper_Initialized);
}
- Create your event handler and have Sitefinity’s ObjectFactory register your class:
void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e) {
if(!ObjectFactory.Container.IsRegistered("PageResolver")){
ObjectFactory.Container.RegisterType("PageResolver", new ContainerControlledLifetimeManager(), new InjectionConstructor());
}
}
You may need to do some cache clearing, but at this point, every title in your site should have “My Site” prepended to the page title.
Bonus: Make it Configurable
I've hardcoded the title of the site in the page resolver class, which isn’t very reusable. It would be much cooler if we could make the title configurable through the backend. Sitefinity actually makes this pretty easy from a coding perspective through its configuration system. I’m not going to outline all the steps in this article, (they’re well-covered in the documentation and in various blog posts) but the high-level tasks you’d need to do are the following:
- Create a Sitefinity module that inherits from ModuleBase
- Create a custom configuration class with a setting for the site name. In my configuration class I actually made two settings: one for site name, and one for a format string:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Sitefinity.Configuration;
using System.Configuration;
using System.ComponentModel;
namespace Copious.Sitefinity.Utilities.Configuration {
public class UtilitiesSettingsConfig : ConfigSection {
[ConfigurationProperty("PageTitleFormatString", DefaultValue = "{0} | {1}")]
public virtual string PageTitleFormatString {
get { return (string)this["PageTitleFormatString"]; }
set { this["PageTitleFormatString"] = (object)value; }
}
[ConfigurationProperty("SiteName", DefaultValue = "")]
public virtual string SiteName {
get { return (string)this["SiteName"]; }
set { this["SiteName"] = (object)value; }
}
}
}
- In your module class, override the GetModuleConfig method and return your configuration class. You’ll also need to override the Initialize method and call Config.RegisterSection, registering your configuration class.
- Modify your page resolver class to use your configuration settings:
var config = Config.Get<copious.sitefinity.utilities.configuration.utilitiessettingsconfig>();
string siteName = config.SiteName;
string pageTitleFormat = config.PageTitleFormatString;
- Install the module, find your configuration section in the Advanced settings in the backend and change them how you like. You’ll now have the ability to format your page titles globally from Sitefinity’s backend.
I hope this post has helped you save some time and frustration setting up page titles in Sitefinity. What other challenges have you run into in Sitefinity? Let me know in the comments and maybe I can expand this post into a series. Interested in joining our engineering team? View open positions »