[development] drupal_add_head -> $page[ 'head'] and hook_alter_page was: Re: global object to push stuff into <head>

Ivan Sergio Borgonovo mail at webthatworks.it
Thu May 7 19:52:11 UTC 2009

On Thu, 7 May 2009 11:27:25 -0400
Moshe Weitzman <weitzman at tejasa.com> wrote:

> > Having a structured head implies having a renderer/theme
> > function (am I right?)
> yes. but core provides some basic ones like #markup so we may not
> need anything new.


> a $page['head'] array sounds good to me.

$page = array(
  'head' => array(
    '#markup' => '<bla bla />',
    'meta' => array(

theme_head($head) {
foreach(...) {
foreach(...) {

$output .= drupal_render($head); // should we really be so verbose?

Other than concat, overwrite what could be done with stuff in head?
I`m just aware of LINK and META and I`m abandoning the idea to offer
some helper function.
It doesn`t seem to have any meaning eg. to duplicate http-equiv
since we can actually send headers.
So if I would like to implement this change I should:
1 double-check what can be placed in head
2 document the structure of page I`m going to use
3 provide a theme_head
4 substitute all the occurrence of drupal_add_html_head with
  hook_alter_page (including stuff in drupal_add_link) [1]
5 change all the occurrences of drupal_get_html_head with ??? [2]

this looks like a revolution and somehow it may end up in changing
head out of context.
In core there are few uses of drupal_add_html_head I`d say that
_alter_page doesn`t look the only candidate where to put stuff that
change head.
keywords and description are generally related to content, you
generate content in the main menu callback function and there you
may collect the right information to build up keywords, description,
If we need to change head other than with _alter_page what other
choices are available?

Actually... drupal_get_html_head is mainly used in
*_preprocess_page... but how other things end up there?
Most of the things that end up in _preprocess_page are globals.
I`m wondering if putting stuff in $page is really worth the
effort... after all $head could be just another global, just
structured. Am I missing something?
$page doesn`t look to be a global, couldn`t other stuff slowly end
there too in spite of having tons of functions containing static?

/me fighting with claws-mail on sid that for some strange reason
transformed the ' key (not the character) into a greedy ^W

function template_preprocess_page(&$variables) {

  $variables['css']               = drupal_add_css();
  $variables['styles']            = drupal_get_css();

?? is it right?

Ivan Sergio Borgonovo

More information about the development mailing list