简体   繁体   中英

custom node template (content type) is not working on drupal 7

After applying following code into template.php, custom node template is not working on Drupal 7. For example, node--article.tpl.php

function jstheme_preprocess_page(&$variables) {
  if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' .    $variables['node']->type;
  } 
}       

If I remove above code, node--article.tpl.php is picking up but not page--article.tpl.php

I assume that it should pick up page--article.tpl.php then node--article.tpl.php if they exist. Is this assumption wrong?

The above code and your assumption is right. I tried using the above code in my local it worked fine, as a result it took page--article.tpl.php as page tpl and for node tpl it took node--article.tpl.php .

Steps to check:

  1. hook_preprocess_page written in template.php will always take the priority.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM