1

I have a parent theme as a basis for a multisite installation. Right now, I'm working on a child theme which has to have some custom templates. Here's my preprocess function in my child theme:

$orig = $vars['theme_hook_suggestions'];
$manual = array('page__node', 'page__node__%', 'page__node__96', 'page__gallery', 'page__drisco_gallery');

dpm(array_diff($manual, $orig));
dpm($manual);
dpm($orig);
$vars['theme_hook_suggestions'] = $manual; // Loads my page--gallery.tpl.php template and works as expected.
$vars['theme_hook_suggestions'] = $orig; // Ignores my template, just uses page.tpl.php

The template only loads if I create the array by hand, even though it's apparently identical to the one already there. Here is what dpm() outputs:

... (Array, 0 elements) 

... (Array, 5 elements)
    0 (String, 10 characters ) page__node
    1 (String, 13 characters ) page__node__%
    2 (String, 14 characters ) page__node__96
    3 (String, 13 characters ) page__gallery
    4 (String, 20 characters ) page__drisco_gallery

... (Array, 5 elements)
    0 (String, 10 characters ) page__node
    1 (String, 13 characters ) page__node__%
    2 (String, 14 characters ) page__node__96
    3 (String, 13 characters ) page__gallery
    4 (String, 20 characters ) page__drisco_gallery

Does anyone have a clue of what I'm doing wrong?

2

In order to load the template based on the content type, inside the template.php file of your theme you need the following code:

function your_theme_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {  
    $vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
  }
}

if the content type is "mycontent," create the page--mycontent.tpl.php file.

For template files that are based on the page path, create the page--front.tpl.php, page--node--7.tpl.php, page--node--58.tpl.php or page--node--nodeid.tpl.php files. Please note that between the page and node templates are different from what they used to be in drupal 6.

  • I am creating a theme hook suggestion for my content type. It is being created in the parent theme as you can see in my DPMs. page__gallery where gallery is the type. My problem is it is being totally ignored. – Joren Dec 28 '11 at 3:01
  • did you try page--gallery.tpl.php make sure it is not page__gallery.tpl.php – 15dk51 Dec 28 '11 at 4:12
  • It is page--gallery.tpl.php – Joren Dec 28 '11 at 18:03
  • Only another thing I can think of is, as this is a subtheme can you add code of theme hook suggestion to your subtheme's template.php file – 15dk51 Dec 28 '11 at 18:19

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.