0

I'm hoping someone can help me because I'm at my wits end! I'm using the zen theme - then created a sub-theme and now I can't seem to get the custom templates to be recognized by the custom content type name (page--node--custom_content_name.tpl.php).

I've created a new template.php in my sub-theme and placed text that I've found in other blogs and forums to help make it recognize the content type so I can use it in the tpl.php name but nothing seems to work. If I use the dev module it only says that I can name them page--node--1.tpl.php, which would be fine if we weren't going to be adding more content on an ongoing basis.

Right now I have so many tpl.php just so that I can show people what the pages will look like - it's crazy!! What am I doing wrong?! Help!!

  • It looks like you are combining two content types (page & node). Are you trying to modify pages or nodes? – RedRaven Jul 28 '13 at 21:17
2

Drupal doesn't provide content type based template suggestions for page.tpl.php but for node.tpl.php. That means you can use a template like node--custom-content-name.tpl.php.

However, if you want to have a page.tpl.php for your content type, you need to tell Drupal about your template suggestion. Put this code in your template.php file:

function YOURTHEME_preprocess_page(&$variables) {
  if (isset($variables['node']->type)) {
    $content_type = $variables['node']->type;
    $variables['theme_hook_suggestions'][] = 'page__' . $content_type;
  }
}

You should name your template file like: page--custom-content-name.tpl.php.

  • Thanks I've tried that too. It still won't work and the devel module isn't showing that it's even possible to name the templates with the content type. so I must be missing some PHP somewhere... I just don't know what. – everaftergraphics Jul 28 '13 at 19:53
  • my devel module shows me my options are this: Template called: sites/all/themes/mazin_theme/templates/page.tpl.php Candidate template files: page--node--31.tpl.php < page--node--%.tpl.php < page--node.tpl.php < page.tpl.php – everaftergraphics Jul 28 '13 at 20:16
  • Ok, I thought Zen theme would provide those template suggestions for page.tpl.php but it is not the case as I read. AdaptiveTheme has an option to activate those template suggestions. In your case you should tell Drupal about them manually. I have updated my answer, please check. – Елин Й. Jul 28 '13 at 21:52
  • Yup - that's it! I just had to create a new template.php and put it in my sub-theme and the only thing in it was a slightly different version: function mazin_theme_preprocess_page(&$vars) { // - page--example.tpl.php if (isset($vars['node'])) { $vars['theme_hook_suggestion'] = 'page__'.$vars['node']->type; // } } – everaftergraphics Jul 28 '13 at 23:06

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.