Thursday, August 25, 2011

Dynamically changing the Drupal Page Title

drupal_set_title (path.inc)

drupal_set_title($title = NULL)

Set the title of the current page, for display on the page and in the title bar.

Parameters

$title Optional string value to assign to the page title; or if set to NULL (default), leaves the current title unchanged.

Return value

The updated title of the current page.

Beware: $title is interpreted as HTML. If you have plaintext strings such as for example $node->title, you must escape them with check_plain or use the correct placeholder in t() before passing them to drupal_set_title(). If you don't, users can execute a cross site scripting attack against your site.

// Incorrect: 
drupal_set_title($node->title);
drupal_set_title(t('Foo !title', array('!title' => $node->title)));

// Correct: 
drupal_set_title(check_plain($node->title)); 
drupal_set_title(t('Foo @title', array('@title' => $node->title)));


No comments:

Post a Comment

Followers