Quick Tips - Custom Modules - Changing the Page Title
NOTE: the concepts presented in this article are now considered obsolete possibly because better alternatives are available.
In an earlier article I showed you how to override the page title using a NotificationSubscriber. This is convenient if you have the need to change the title for all or many pages in your site. However, when building custom modules, you may have the need to change the title for a specific page only. Fortunately, this is very easy to do in a custom module.
The ContentModule class, the base class for all your custom modules, has a Pageview property of type PageView (note the inconsistency in capitalization, something you need to be aware of when using C#). This PageView property in turn has a Meta property that lets you set the page title through its Title property.
To set the page title in your custom module, you can use the following code:
[AddInName("YourModuleName")] public class Frontend : ContentModule { public override string GetContent() { // Other code here to create HTML Pageview.Meta.Title = "Your custom page title here"; // Other code here to return the HTML } }
When rendered in the browser, your page title ends up between the <title> tags in the <head> section of your page.