0

Slowly losing my mind here:

I need to make a template for the terms of a certain vocabulary. I created a sub-theme and am trying to use theme_preprocess_page() ( theme_preprocess_taxonomy_term() is somehow never called ).

template.php

function aura_sub2_preprocess_page(&$variables) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $term = taxonomy_term_load(arg(2));
    drupal_set_message( 'page__vocabulary__' . $term->vocabulary_machine_name );
    $variables['theme_hook_suggestions'][0] = 'page__vocabulary__' . $term->vocabulary_machine_name;
  }
}

As you can see I even overwrite the first suggestion for testing purposes but it changes nothing. The page loads as if nothing ever happened. When I open "mydomain.com/?q=en/myvocabulary/someterm" I get the status message "page__vocabulary__myvocabulary". So far so good but the template suggestions is seemingly ignored. The template resides in the "theme" directory of that sub-theme. I tried every possible combination of "--" and "__" to no avail. The template only contains this, is that a problem?:

theme/page--vocabulary--myvocabulary.tpl.php

<h1>MYVOCAB TEST</h1>

Cache has been cleared each time, no change. :c

Any ideas?

andrbmgi
  • 528
  • 3
  • 17

1 Answers1

0

I think it may be because you are adding the suggestion to the start of the array rather than the end.
replace:

$variables['theme_hook_suggestions'][0] = 'page__vocabulary__' . $term->vocabulary_machine_name;

with:

$variables['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name;
2pha
  • 9,798
  • 2
  • 29
  • 43
  • That did not work unfortunately. Of course this is the correct way of action. – andrbmgi Sep 17 '14 at 09:02
  • is your preprocess function actually getting called? – 2pha Sep 17 '14 at 12:05
  • Yes, to check that I set a status message that is displayed on the page. The status message also tells the suggestion the function puts in the list. So all of this seemingly works but it has no effect whatsoever on the rendering of the page. – andrbmgi Sep 17 '14 at 17:08
  • What is the template file name? Are you 100% sure it is correct? and that it is in the correct folder? – 2pha Sep 17 '14 at 17:16
  • Not sure about that, I tried every possible single-dash/-underscore and double-dash/-underscore combination of "page--vocabulary--myvocabulary.tpl.php". It sits in the folder "theme". Is that how it should be? – andrbmgi Sep 17 '14 at 21:54
  • I'm not sure if the .tpl file should be in a folder named 'theme'. Have you tried it just in your theme folder? The structure of the file name looks ok to me. Are you sure you are using the vocabulary machine name in the template file name? – 2pha Sep 18 '14 at 03:51
  • Did you try `drush cc theme-registry`? – artfulrobot May 01 '15 at 06:22