1

I've got a well-established theme that's building a lot of variables for the page template, ie. $variables['page']['stripe_color'] = $some_node_data; However, now I'd like to apply this variable to the body tag; so, it needs to be communicated to html.tpl.php

I know there's a bunch of ways to this, store it in a global, reevaluate in the theme_preprocess_html, but I'm wondering if there's a simple variable somewhere that's available that I'm not finding.

0

Sounds like a perfect use case for the more generic hook_preprocess:

function MYTHEME_preprocess(&variables, $hook) {
  if ($hook == 'page' || $hook == 'html') {
    $variables['shared_var'] = 'foo';
  }
}

$shared_var will be available in both html.tpl.php and page.tpl.php. This will be processed twice, so if it's expensive to build the vars, make sure you statically cache them.

  • And I assume $hook == 'page' is called before $hook == 'html'? – Get the Jaws of Life Jun 10 '16 at 14:50
  • Don't have to time to check right now but I'm 99% certain it does, yes – Clive Jun 10 '16 at 15:03

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.