I have created my first Zen sub-theme. I really like it so far, thanks!
Anyway, I am having trouble with template suggestions. I have created a Drupal 7 site. I created a sub theme and put the page.tpl.php file in the templates folder. I have also placed the node.tpl.php file in this folder. I created a file, node--webform.tpl.php and I am able to successfully change the template used for all webforms. So now I want to change the output of a specific webform, so I created another file, page-node-6.tpl.php. However, this new template suggestion is not recognized. I thought perhaps this didn't work for webforms, so I created a test page, and tried a new template suggestion for it- page-node-8.tpl.php, and it did not work either!
Any suggestions? I think I have all the base templates in the templates folder. I think I have the names right (I have used this method many times in D6, I know they changed a few things in D7, so perhaps I didn't do the names right?)
Comments
Comment #1
johnalbinI believe the proper name should be page--node-6.
Comment #2
ensignavenger commentedThanks, I used the excellent Theme Developer module and found that the correct name to override the node.tpl.php is node--6.tpl.php.
Now I would like to override the page.tpl.php on page content types, you can use node--page.tpl.php to overide ALL page content items, but I can find no way to override only a specific pages page.tpl.php (tried node--page--8.tpl.php, also tried page--8.tpl.php, but neither worked.
According to http://drupal.org/node/190815, page-node-8.tpl.php should work, but it seems not to. Theme Developer does not make any suggestions for a specific pages page.tpl.php.
Any suggestions are most helpful.
Comment #3
ensignavenger commentedBTW, I did try page--node-8.tpl.php, as suggested above, but it did not work.
Comment #4
vinsabus commentedHow about node--page-8.tpl.php ?
Comment #5
n8tronpage--node--8.tpl.php seemed to work for me.
Comment #6
vinsabus commentedJust re-read your description, not sure if you want to customize the output of a page or style a specific webform. if you want to target a specific webform shouldn't the file be node--webform-8.tpl.php or node--webform--8.tpl.php
Comment #7
ensignavenger commentedSorry for not responding sooner. I was working on another issue that kept me from testing your suggestions. The documentation has been updated at http://drupal.org/node/1089656 to clarify the correct names. The correct name for overriding a specific page is page--node--7.tpl.php, which seems to work for both regular pages and webforms.
Thanks to everyone who responded.
Comment #8
kborer commentedFor Drupal 7, to theme the form used by webform use webform-form-nid.tpl.php
Comment #9
jerilcjs commentedTemplate suggestions did not work when I was using Drupal 7.12. For Drupal 7.9 page--node--1.tpl worked fine..?
Comment #10
hessam61 commentedThis doesn't work for webform on Drupal 7.15. I cannot override page template using "page--node--7.tpl.php" or "page--node-7.tpl.php". Any suggestion?
Comment #11
madymad commentedCopy following code to ur template.php file with replacing "ur_theme_name" to ur theme name and use the tpl file name as "page--node--1.tpl.php" for node and for content type "page--[ur_content_type]--%.tpl.php" will work.
function ur_theme_name_preprocess_page(&$vars) {
// Do we have a node?
if (isset($vars['node'])) {
// Ref suggestions cuz it's stupid long.
$suggests = &$vars['theme_hook_suggestions'];
// Get path arguments.
$args = arg();
// Remove first argument of "node".
unset($args[0]);
// Set type.
$type = "page__type_{$vars['node']->type}";
// Bring it all together.
$suggests = array_merge(
$suggests,
array($type),
theme_get_suggestions($args, $type)
);
// if the url is: 'http://domain.com/node/123/edit'
// and node type is 'blog'..
//
// This will be the suggestions:
//
// - page__node
// - page__node__%
// - page__node__123
// - page__node__edit
// - page__type_blog
// - page__type_blog__%
// - page__type_blog__123
// - page__type_blog__edit
//
// Which connects to these templates:
//
// - page--node.tpl.php
// - page--node--%.tpl.php
// - page--node--123.tpl.php
// - page--node--edit.tpl.php
// - page--type-blog.tpl.php << this is what you want.
// - page--type-blog--%.tpl.php
// - page--type-blog--123.tpl.php
// - page--type-blog--edit.tpl.php
//
// Latter items take precedence.
}
}