Preprocess variables for page.tpl.php

Preprocess variables for page.tpl.php

Most themes utilize their own copy of page.tpl.php. The default is located inside "modules/system/page.tpl.php". Look in there for the full list of variables.

Uses the arg() function to generate a series of page template suggestions based on the current path.

Any changes to variables in this preprocessor should also be changed inside template_preprocess_maintenance_page() to keep all of them consistent.


glass.dimly’s picture

You can implement this hook in a module with MODULENAME_preprocess_page.

ShaneOnABike’s picture

If folks want a nice little snippet that adds a bunch of dynamic suggestions you could add...

 // Do we have a node?
  if (isset($vars['node'])) {

    // Ref suggestions cuz it's stupid long.
    $suggests = &$vars['theme_hook_suggestions'];

    // Get path arguments.
    $args = arg();
    // Remove first argument of "node".

    // Set type.
    $type = "page__type_{$vars['node']->type}";

    // Bring it all together.
    $suggests = array_merge(
      theme_get_suggestions($args, $type)

    // if the url is: 'http://domain.com/node/123/edit'
    // and node type is 'blog'..
    // This will be the suggestions:
    // - page__node
    // - page__node__%
    // - page__node__123
    // - page__node__edit
    // - page__type_blog
    // - page__type_blog__%
    // - page__type_blog__123
    // - page__type_blog__edit
    // Which connects to these templates:
    // - page--node.tpl.php
    // - page--node--%.tpl.php
    // - page--node--123.tpl.php
    // - page--node--edit.tpl.php
    // - page--type-blog.tpl.php          << this is what you want.
    // - page--type-blog--%.tpl.php
    // - page--type-blog--123.tpl.php
    // - page--type-blog--edit.tpl.php
    // Latter items take precedence.
kevinsiji’s picture


If you use hook_preprocess_node in a theme file, it works only for that theme. Once you change the theme, you loss the feature you add via this function.


If the hook is in a module, you will have your functionality even when you swap the themes.

I've no idea about the performance implications.

ranelpadon’s picture

$variables['title'] is available in the template_process_page: