1

I have a taxonomy term page being displayed via a Views 'page' display. I need to change a value in the header of the site (above the level of the view) based on the value of one of the fields in the taxonomy term.

The problem is that I can't find the right hook for this. If I hook into hook_preprocess_views_view, it's too late. The wrapper that includes the site header has already fired. If I try to run hook_preprocess_page, there isn't yet any information in the $variables arg to give me the taxonomy ID so I can look up the field value. Unless there is are variables available to the hook in addition those that are passed into function as args, I don't see how I can get the requisite information. Are there other variables I could use that are undocumented or global variables available that just aren't passed to the function/hook?

1 Answer 1

0

What you can do is in the hook_preprocess_page use the following code :

$arg = arg();
if (count($arg) == 3 && $arg[0] == 'taxonomy' && $arg[1] == 'term' && is_numeric($arg[2])) {
  $term = taxonomy_term_load($arg[2]);
  if ($term->vid == $my_vocab_id) {
    # code...
  }
}

Then change the value of the header as you want in the # code... part.

Basically you check if the URL is a taxonomy term page and then you can check that the term vid correspond to its proper vocabulary id.

Hope that will help you.

1
  • 1
    I see. That function is helpful. That's exactly what I needed.
    – undefined
    Oct 28, 2014 at 17:13

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.