This project is read-only.

Overriding the page <title> tag

Topics: Writing modules
Mar 31, 2011 at 7:41 AM

I'm taking a shot at extending Vandelay.Meta to allow for the title tag to be overridden (for SEO purposes when you don't want it to be the same as the H1 heading on the page).

It looks like IPageTitleBuilder is the interface that handles page title generation.  But if I create a new class:   public class PageTitleBuilder : IPageTitleBuilder and change the Generate() method it doesn't seem to get called.

How do I get my implementation of IPageTitleBuilder to be the one that gets called? or is there an easier / better way to change the title tag on the page?

Mar 31, 2011 at 7:44 AM

Just setting Layout.Title should do the trick.

Mar 31, 2011 at 7:45 AM

Alternatively, you might want to hide the part that renders the title in h1 using placement or by overriding the template.

Mar 31, 2011 at 7:46 AM

How do I do it in a Driver?  I was looking at your MetaDriver class.

Mar 31, 2011 at 7:49 AM

And I want to keep the H1 tag: SEO optimized pages need both an H1 (full length) and a <title> tag optimized for display in search engines (i.e. skipping some words to fit in the visible width).  (See our earlier discussion on this topic)

Mar 31, 2011 at 7:51 AM

From a driver, get the work context, Layout is a property of it.

Mar 31, 2011 at 9:08 AM

I tried various things in the driver but cannot seem to override the page title.  Any more hints?

Mar 31, 2011 at 9:17 AM

It looks like Document.cshtml ignores the whole PageTitleBuilder class and just makes up a title on its own.  So what's the purpose of PageTitleBuilder then?

    var title = (Request.Path != Request.ApplicationPath && HasText(Model.Title)                    ? Model.Title + WorkContext.CurrentSite.PageTitleSeparator                    : "") +        WorkContext.CurrentSite.SiteName;

Mar 31, 2011 at 6:35 PM

Here's a proposed work item to fix it: