Skip to main content
update explanation for node page template
Source Link
Shawn Conn
  • 26.9k
  • 15
  • 49
  • 73

Havepage.tpl.php doesn't know, by itself, anything about node types so you'll have to make your module preprocess the page with hook_preprocess_HOOK() to add an alternative theme hook suggestion.

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

Once done, you can have your module evoke hook_theme() to advertise processing for your custom page node type template and its location. For example:

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['node__mynodetype']$theme['page__mynodetype'] = array(
    'path' => drupal_get_path('module', 'MYMODULE') . '/templates',
    'template' => 'node'page--mynodetype',
  );
  return $theme;
}

When the module is enabled (and theme registry cache cleared), the theme engine will look for nodepage--mynodetype.tpl.php within the templates directory of your module.

Have your module evoke hook_theme() to advertise processing for your custom node type template and its location. For example:

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['node__mynodetype'] = array(
    'path' => drupal_get_path('module', 'MYMODULE') . '/templates',
    'template' => 'node--mynodetype',
  );
  return $theme;
}

When the module is enabled (and theme registry cache cleared), the theme engine will look for node--mynodetype.tpl.php within the templates directory of your module.

page.tpl.php doesn't know, by itself, anything about node types so you'll have to make your module preprocess the page with hook_preprocess_HOOK() to add an alternative theme hook suggestion.

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

Once done, you can have your module evoke hook_theme() to advertise processing for your custom page node type template and its location. For example:

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['page__mynodetype'] = array(
    'path' => drupal_get_path('module', 'MYMODULE') . '/templates',
    'template' => 'page--mynodetype',
  );
  return $theme;
}

When the module is enabled (and theme registry cache cleared), the theme engine will look for page--mynodetype.tpl.php within the templates directory of your module.

Source Link
Shawn Conn
  • 26.9k
  • 15
  • 49
  • 73

Have your module evoke hook_theme() to advertise processing for your custom node type template and its location. For example:

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['node__mynodetype'] = array(
    'path' => drupal_get_path('module', 'MYMODULE') . '/templates',
    'template' => 'node--mynodetype',
  );
  return $theme;
}

When the module is enabled (and theme registry cache cleared), the theme engine will look for node--mynodetype.tpl.php within the templates directory of your module.