I have an html template variable called "sitepage" that needs to be set by a module based on node relationships.

Is there a way to set html.tpl variables from a module?

function dc_preprocess_html(&$vars)
    $vars['sitepage'] = '/*Insert Business Logic as described below*/';

The logic for what the sitepage should be is as followed:

  1. If we are on a car model or car make page then find the car make node and check to see if there is a node reference to an Advertiser node.
  2. Using the advertiser node, check the field "field_sponsor_site_page" to determine the site page

I can easily do this in the module code, but need to do this so I can put the variable in html.tpl.php

The way it works now:

I have 2 pages in play:

  1. Car Detail Page: model/[Car Make Node FIELD_COLLECTION_ID]
  2. List Cars of a particular model: makes/[Car Make Node Id]

A car make node has a node reference to Advertiser. The advertiser has a sitepage that needs to be inserted into html.tpl.php in both cases based on this business logic

  • 1
    Really not following you here, you've already answered the question in the question...you use template_preprocess_html. Assuming your module is called dc all you need to do is fill in the 'easy' business logic part and you're done. What have I missed?
    – Clive
    Feb 21, 2013 at 15:09
  • The code for the business logic is in a module called dc_car_guide but I need to set a variabled $sitepage in html.tpl.php I will update question with more details Feb 21, 2013 at 15:12
  • Do you realise modules can also implement preprocess hooks in exactly the same way? Just call the function dc_car_guide_preprocess_html...
    – Clive
    Feb 21, 2013 at 15:15
  • that seems to work, but It seem the module preprocess_html is called before the template preprocess. How is the order determined? Feb 21, 2013 at 15:40
  • Yes hooks for modules are always run first. Why would you need it to run after the theme layer?
    – Clive
    Feb 21, 2013 at 15:58

1 Answer 1




to alter the hooks order

  • How is order determined anyways? Feb 21, 2013 at 15:50
  • its based on the module name acctually ...
    – Pan Chrono
    Feb 21, 2013 at 15:51
  • It's based on a few factors not just module name. There's a question on the site somewhere that explains it really well ill try to dig it out...
    – Clive
    Feb 21, 2013 at 15:55
  • drupal.org/node/110238 Good call for a better search, cheers
    – Pan Chrono
    Feb 22, 2013 at 17:57

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.