6

H i I am quite new in Drupal and have been trying to figure out a way to assign a specific template file to some specific pages following the taxonomy like page--user--edit.tpl.php works but I don't want to create a single template file for each page I require to change. I have been trying the following code but this doesn't work for me is there any cleaner way to achieve this in drupal 7

function phptemplate_preprocess_page(&$vars) {
 if (arg(0) == 'node' && (arg(1) == '10')) {
   $vars['template_files'][] = 'page-sometest';
 }
1

2 Answers 2

10

See here Drupal 7 Theme Hook Suggestions

For nodes You can use

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

base template: node.tpl.php

Theme hook suggestions are made based on these factors, listed from the most specific template to the least. Drupal will use the most specific template it finds:

node--nodeid.tpl.php

node--type.tpl.php

node.tpl.php

Also Drupal 6 Template Suggestions

To use same tpl for multiple pages you need to use theme_preprocess_node Like

function theme_preprocess_node(&$vars, $hook) {
  $node = $vars['node'];
  if(in_array($node->nid), $myuids)
   $vars['template_file'] = 'your_template_file';
}
1

The Drupal way to do this is to create a specific template file for each page. Trying to override the theme system in this manner will create a mess if your site grows larger and becomes more complex.

If you don't want to create a file per page, I would recommend learning how to use the Panels module. It does take some time to learn, but Panels provides an interface that allows you to relatively easily customize the layouts to any node or groups of nodes (content types, etc.) on your site. If you've never used Panels before, I recommend Node One's introduction.

1
  • is there a reason why writing this function in template.php didn't work for me function phptemplate_preprocess_page(&$vars) { if (arg(0) == 'node' && (arg(1) == '10')) { $vars['template_files'][] = 'page-sometest'; } Commented Apr 25, 2012 at 11:06

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.