8

I'm trying to allow users to update head titles and meta descriptions for each page. I thought that an easy way to achieve this would be to add a field to the 'Basic page' content type for the page title, then check if that field is not empty in html.tpl.php and if it is not, override $head_title with this user-defined value.

However, it appears that the $node variable is not available in html.tpl.php. Can anyone suggest a way for me to make this data available in this template file, or alternatively, alter $head_title before it is sent to html.tpl.php? Thanks for reading.

2 Answers 2

9

Taken in part from this thread that I found: http://drupal.org/node/1041768...

In your template.php, you can do the following:

function yourtheme_preprocess_html(&$variables) {
  // If on an individual node page, add the node type to body classes.
  if ($node = menu_get_object()) {
    $variables['head_title'] = $node-> // find your cck field here
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Question... can something like this allow me to display $title in my html.tpl.php?
@Matthew: Not sure what you mean, but I suggest you clarify and expand your question as a new one. You can link and refer to this question if you want to, but you'll get more answers if you post this as a separate question.
3

Bit messy, but would work:

if(arg(0) == 'node' && !empty(arg(1))) {
  $node = node_load(arg(1));
}

However, you might prefer http://drupal.org/project/metatags_quick (an interrim module until the full http://drupal.org/project/metatags is finished).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.