hook_preprocess_page
is the preprocess hook invoked when the page.tpl.php template file is used, and hook_preprocess_html
is the preprocess hook invoked when the html.tpl.php template file is used.
Both the preprocess hooks are invoked when a page is rendered with theme('page')
, since the page element defined from system_element_info() defines html as theme wrapper.
$types['page'] = array(
'#show_messages' => TRUE,
'#theme' => 'page',
'#theme_wrappers' => array('html'),
);
system_theme() then defines html as follows.
'html' => array(
'render element' => 'page',
'template' => 'html',
),
As for when to implement hook_preprocess_html()
, you implement it to alter the variables used in the html.tpl.php file, which by default has the following content.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language; ?>" version="XHTML+RDFa 1.0" dir="<?php print $language->dir; ?>"<?php print $rdf_namespaces; ?>>
<head profile="<?php print $grddl_profile; ?>">
<?php print $head; ?>
<title><?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
<body class="<?php print $classes; ?>" <?php print $attributes;?>>
<div id="skip-link">
<a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
</div>
<?php print $page_top; ?>
<?php print $page; ?>
<?php print $page_bottom; ?>
</body>
</html>
As you can see, it contains just the HTML tags that wrap a page content, available in $page
. With that, you can change the content of the <head>
tag, the page title (the one that goes in the <title>
tag in the <head>
tag), the CSS styles and the JavaScript files added to a page, the classes and the attributes for the <body>
tag.
With the page.tpl.php template file, you can change more of the page being rendered, including the site name, the site slogan, the page title, and the feeds associated with the page. For most of them, there is a specific Drupal function/hook you should instead use.
hook_preprocess_HOOK
is the generic hook name used for all the preprocess hooks, in the same way hook_form_FORM_ID_alter()
is the hook name used for a class of alteration hooks.
template_preprocess_page()
is different fromhook_preprocess_page()
, and there is documentation for hook_preprocess_HOOK, in the same way there is for hook_process_HOOK.