Tech4Him – Technology with Integrity

A Christian technology chaos wrangler and his thoughts

Drupal $head_title versus $title. Split ‘em.

Posted by admin On June - 27 - 2007

So, you built a nice new PHPTemplate theme. You followed the samples
and in your <title> tag, you place the $head_title
variable and in your section header you display the $title variable.
They are different titles, or are they?

Short answer is yes, they are. However if the module generating page content happens to use the drupal_set_title() function, then the value of both title variables will be the same. This is not always what you want.

Some quick reading and modification of our template.php file resolved this for us.

function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
switch ($vars['node']->type) {
case 'project':
$vars['head_title'] = $vars['node']->title;
break;
case 'quarterlyreport':
$vars['head_title'] = $vars['node']->title;
break;
}
break;
}
return $vars;
}

The
key here is that the node attributes are accessible in the
_phptemplate_variables function of the PHPTemplate. Therefore we can
create conditional logic based upon node->type, node->status,
etc…

Finally, any of the template engine variables are
accessible and can be set or unset prior to the generation of the
output. Remember the $head_title variable? See how we modify it based
upon node properties.

Popularity: 9% [?]

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • PDF
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Leave a Reply