Custom titles controlled by views

One of the things which is pleasing about having (finally) built the site and running HEAD of InForm is that it gives me the chance to really tweak and optimise things on a live site without needing to co-ordinate things with anyone other than myself. While browsing Google Webmaster, I noticed that it was complaining that I had 79 Duplicate title tags which I found somewhat surprising. On closer inspection it appeared that this was because the title that is generated when you ask to see a zoomed version of an embedded image is the same as the default title for a page. Therefore if you have a page with 6 zoomable images then Google will see 7 pages with the same title.

Unfortunately this has a few hoops to jump through. The <title> tag is rendered in the <head> of a page, but the view that is responsible for carrying out the actions and outputting the results is in the <body> which follows on from the <head>. Therefore if we need our <title> to be customisable by the view being invoked then we have to look at the ordering of when which element gets invoked.

As it happens, InForm rendering works by traversing down the pages in an incoming request and asking each view for each level (read views for parent pages, and whatever the target view is for the destination page) to decide whether or not the request is valid and if it is then to define which templates should be utilised when the templates are finally rendered. The original motivation behind this was to make it so that any element in the system was hot swappable, but it also has the advantage that we can alter our rendering pass to the following sequence of events:

  1. perform any global initialisation of state that will be needed for both the <head> and the <body> template rendering systems.
  2. traverse the incoming request and set up the template tree such that the <body> can be rendered in the future. This will involve invoking view-specific templates which means that this is the point when we can customise the behaviour of the <head> templates.
  3. render the <head> template which will now include any of the customisations introduced in the previous step
  4. invoke the template tree set up in the second stage to render the <body> of the page

The end result of this is that we now have the architecture to let the view templates to customise any part of the page rendering, not just the template tree inside the <body>.

Back Garden View

This image has a title which will be used when zoomed

This image is untitled so a default title will be used when zoomed

I have implemented an extension to the default title rendering engine so that you can either declare $title_explicit which replaces the entire of the default title, or $title_extra which includes the value in addition to the default template. The rendering algorithm for the zoomed image utilises this to set up $title_extra which includes either the title of the zoomed image into the <title>, or if this is not defined then a title that includes the id of the image.

If you zoom in the images to either side of this paragraph and look at the page title then you will see that it now includes the appropriate information to distinguish it from the default page view. Once google re-indexes the pages then we should see the warnings disappear from webmaster, and hopefully better page performance as a result.

We will need to sweep through all the publicly accessible views in the InForm hierarchy working out which other ones are being picked up by google and therefore are a priority for altering the <title> tags, but webmaster will help us identify the most likely candidates.