page-node-nid.tpl.php is not used as template file

by Владимир Помелов   Last Updated November 18, 2017 08:07 AM

I am using the following code.

function chgakitheme_preprocess_page(&$vars, $hook) {
  if ($vars['user']->uid == 0 && arg(0) == 'user' && (arg(1) == '' || arg(1) == 'login')) {
    array_unshift($vars['template_files'], 'page-login');
    $vars['body_classes'] .= ' userlogin';

  if (isset($vars['node'])) {
   $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);

Now I can use page-nodetype.tpl.php, but I can't use page-node-nid.tpl.php because Drupal doesn't see it.

I need all types of template files. I want a template specific for a content type.

What can I do? Can I do this in Drupal 6?

Tags : theming 6

Answers 1

Have a look at the Drupal 6 Template suggestions, The list of suggested template files is in order of specificity based on internal paths. One suggestion is made for every element of the current path, though numeric elements are not carried to subsequent suggestion, order of execution is as below:

  • page-node-edit.tpl.php
  • page-node-[node_id].tpl.php
  • page-node.tpl.php
  • page.tpl.php

So basically you don't need to use the "TEMPLATE_preprocess_page" for using "page-node-[node_id].tpl.php" for template suggestion as it is provided by default. May be the problem is of "clearing the cache", try once after clearing the cache.

In Drupal6, page-node-[node_type].tpl.php is not available by default, to make it work we customize the suggestions in the TEMPLATE_preprocess_page as done by you.

If you want more specific templates than you can customize the template suggestions as your requirement in TEMPLATE_preprocess_page. Example as below:

// Implement TEMPLATE_preprocess_page.
function TEMPLATE_preprocess_page(&$variables) {
  if ($variables['node']->type !== '') {
    // For using "page-node-[node_type].tpl.php" for template suggestion.
    $variables['template_files'][] = "page-node-" . $variables['node']->type;

    // For using "page-node-[node_type]-[node_id].tpl.php" for template suggestion.
    $variables['template_files'][] = "page-node-" . $variables['node']->type . "-" . $variables['node']->nid;

After using the above code you can use the additional template suggestion as below:

  • page-node-[node_type]-[node_id].tpl.php
  • page-node-[node_type].tpl.php

NOTE: Don't forget to clear the cache after making changes to template files otherwise the changes won't reflect back.

Ankit Agrawal
Ankit Agrawal
October 19, 2013 16:18 PM

Related Questions

Features can export everything?

Updated March 26, 2015 10:02 AM

No image style found

Updated March 29, 2015 15:02 PM

Best way to have 5 or 6 themes in one site drupal 7

Updated April 09, 2015 22:03 PM