1

I have this preprocess function:

function drisco_preprocess_page(&$vars) {
    $node = $vars['node'];
    $vars['theme_hook_suggestions'][] = 'page__node__' . clean_class($node->title);
    array_unshift($vars['theme_hook_suggestions'], 'page__node__' . clean_class($node->title));
    dpm($vars);
}

dpm() tells me my suggestion array looks like this:

0 (String, 26 characters ) page__node__hotel-overview
1 (String, 10 characters ) page__node
2 (String, 13 characters ) page__node__%
3 (String, 14 characters ) page__node__68
4 (String, 10 characters ) page__page
5 (String, 11 characters ) page__hotel
6 (String, 26 characters ) page__node__hotel-overview

My template file is called "page--node--hotel-overview.tpl.php" but isn't being used. I have page.tpl.php template file in my theme dir.

What am I doing wrong?

If I erase the template suggestions array and replace it with my own with only one file in it like thus, it loads the template. If I append or prepend the same suggestion, it just loads page.tpl.php.

$vars['theme_hook_suggestions'] = array('page__node__68');

This is a child theme; could that be making a difference?

1

Let me explain you the template order

In this, you can alter the header and footer if you wanted it to be different than normal page layout that is set in the page.tpl.php

page--[content-type name].tpl.php = page--lab.tpl.php It will be used to theme all contents of type lab including header and footer

page--node--[content-id].tpl.php = page--node--12.tpl.php It will be used to theme content with 12 including header and footer

Secondly,

  1. node.tpl.php Will work for all type of content on the site
  2. node--[content-type name].tpl.php (node--lab.tpl.php) will used to alter the content part only of lab type content excluding header and footer
  3. node--[node-id].tpl.php(node--10.tpl.php) will use to alter the content part of node 10 only excluding header and footer

Including and excluding meand control over header and footer.

Hope it will help you!

0
  1. Clear the caches to ensure your new template file is being picked up.
  2. The template file should be in the "templates" folder inside your custom theme.
  • Cleared cache a bunch. My node doesn't have a machine name. hotel-overview is its title just strtolower'd and spaces replaced by dashes. – Joren Dec 23 '11 at 23:04
  • every content type has a machine name. – PhiloSurfer Dec 23 '11 at 23:05
  • I edited my comment because i read your question wrong... make sure the file is in the templates folder in your theme – PhiloSurfer Dec 23 '11 at 23:06
  • Hmm. I didn't realize about the templates folder, but moving them there didn't seem to help. – Joren Dec 23 '11 at 23:22
  • try it with the node id just in case... – PhiloSurfer Dec 23 '11 at 23:26
0
  1. The naming of both your suggestion and template look legit.
  2. If I read this correctly, the suggestions array should be sorted from more general suggestions (on the top) to more specific suggestions (on the bottom). Not sure why you are using array_unshift to prepend the most specific suggestion to the beginning of the array. Also, could it be that putting the same suggestion in the array twice is throwing off the theming layer?
  3. Did you check to make sure that the 'theme_hook_suggestion' key is empty? It accepts a single value that takes precedence over the 'theme_hook_suggestions' key. Just out of curiosity, what happens if you use it? If you populate theme_hook_suggestion and still your template does not get called, I would be more wary of #5 below. If it does get called, maybe I would be concerned about what I said on #2 above.
  4. Where are you implementing that hook, in template.php or a module? There's a chain of preprocessing hooks called by theme() every time, and depending where your hook is it might or might not be getting overridden by another hook down the theme() preprocessor chain. Very unlikely your case I think, but it's not impossible. If your hook is being implemented in the module layer, move it to the theme layer and see what happens. The theme layer has higher precedence - it gets called after the module layer.
  5. It looks like your problem is the location of the template itself. A) What is the value of $theme_path and $info if you run this code below? B) Is your template currently located where $theme_path below points to?

_

  drupal_theme_initialize();
  $hooks = theme_get_registry(FALSE);

  $info = $hooks['page'];
  global $theme_path;
  $temp = $theme_path;
  // point path_to_theme() to the currently used theme path:
  $theme_path = $info['theme path'];
0

I am thinking it can't have a - in it anywhere, eg, in hotel-overview, because these could be theme functions as well, and obviously, php wouldn't like function theme_page__node__hotel-overview() so I'd change all the -'s to _'s in your sanitized title and see if it finds it (but keeping the dashes in the template name)

0

For the template file:
THEME/templates/page--node--hotel-overview.tpl.php

try:
page__node__hotel_overview

Hyphens in templates filename are converted to underscores, both singles and doubles.

Edit: Woops, this was acutally quite old. My bad.

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.