2

So I am new to Drupal and I am trying to create a new theme for a site. I am trying to create a page template for a specific custom content type. Research has led me to adding this to my template.php file:

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

However, it is not working. I know the template.php file itself is being pickup up because a simple echo test works, but putting one in the function above does not fire. So I have to assume this function is not being called. I changed the 'yourthemename' to what I think is my theme's machine name. The folder name and .info name is FWMurphy. I tried that and fwmurphy and neither worked. I am stumped.

3
  • 2
    Use the exact case. Also did you clear your cache ??
    – junedkazi
    Commented Oct 10, 2012 at 17:19
  • 1
    Btw, avoid using different case in theme/module names. Commented Oct 10, 2012 at 17:50
  • Still not working
    – BobbyDank
    Commented Oct 10, 2012 at 19:14

2 Answers 2

2

In your instance the hook should be (based on what you said your theme name is):

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

After you implement that, clear the drupal cache. For drupal to pickup your page--{node type}.tpl.php , you need to make sure your theme also contains a default page.tpl.php

1
  • Still not working. Like I said. Its like the function itself is never being fired.
    – BobbyDank
    Commented Oct 11, 2012 at 15:58
2

Okay. I ended up figuring out what was wrong. Given what I needed done and the info given here, there is no way anyone could have helped me with this, so sorry and thank you to all who tried.

Come to find out my .info file was named wrong. It was named theme.info instead of fwmurphy.info so it was throwing off the machine readable name for my theme. Once I renamed it and replied the theme, everything worked as it should.

Again thanks everyone.

2
  • 1
    Without proper information nobody can help you. Nobody can guess but can help only by given description of yours. I don't find any wrong with answer below..
    – RajeevK
    Commented May 29, 2013 at 10:36
  • Thanks for sharing, the same thing was happening to me, 2 days to find this answer. So blessed you shared it.
    – Dazag
    Commented May 6, 2020 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.