4

In Drupal 6, if you had a content type with the system name "stock-photo", you could override it using:

node-stock-photo.tpl.php

How do you do this in Drupal 7?

2

You can add custom node.tpl.php for any kind of content type like

node--[node-type].tpl.php

I would suggest you to use hook suggestion at template.php for this :

function MYTHEME_preprocess_page(&$variables, $hook) {  // Add theme suggestion for all content types
    if (isset($variables['node'])) {
        if ($variables['node']->type != '') {
            $variables['theme_hook_suggestions'][] = 'page__node__' . $variables['node']->type;
        }
    }
}

So that I can have node--wine.tpl.php for content type wine.

Note -- Don't forget to clear your cache after this :)

  • 1
    What's the purpose of the PHP hook suggestion function? – Ken Williams Oct 20 '15 at 3:22
5

I think MYTHEME_preprocess_page() function doesn't need for it.

The node--[node-type].tpl.php is only enough for it.

  • That worked for me :) – Gladiator Aug 11 '14 at 8:17

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.