In my module I have verified this function is being called, but when I try to edit page--golfguide--alias.tpl.php it doesn't have the variables available.

In module:

function dc_branding_preprocess_page(&$vars) 
    $vars['branded_header'] = dc_branding_header_contents();
    $vars['branded_footer'] = dc_branding_footer_contents();

In template.php for theme:

function golfguide_preprocess_page(&$vars, $hook) 
    global $user, $is_mobile;
    if (isset($vars['node'])) 
      // If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
       $vars['theme_hook_suggestions'][] = 'page__'.$vars['node']->type;

      // If the node id is "33" the template suggestion will be "page--33.tpl.php".
       $vars['theme_hook_suggestions'][] = 'page__'.$vars['node']->nid;    
    //Create page suggestion for first part of url-alias
    $url_alias = drupal_get_path_alias($_GET['q']);
    $parts = explode('/', $url_alias);
    $parts[0] = str_replace('-', '', $parts[0]);
    $vars['theme_hook_suggestions'][] = 'page__'.$parts[0].'__alias'; 

        $vars['theme_hook_suggestions'][] = 'page__'.$parts[0].'__mobile';  

In page--golfguide--alias.tpl.php

<?php print render($page['branded_footer']); ?>

NOTHING outputs and the key branded_footer does not exist.

  • Try setting your vars in golfguide_preprocess_page(). Sep 18 '13 at 23:35
  • I need to do this for every theme when the module is enabled. Sep 18 '13 at 23:53

You are trying to render $page['branded_footer'], but the module preprocess function is setting $vars['branded_footer'], which would be accessible as $branded_footer in the template file.

$page['branded_footer'] would be set if the theme defines a branded_footer region. In that case, you should follow what How do I create custom regions in a theme? says.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.