I have two page template files, one that is just 'page.tpl.php' and another for a subset of pages.
How can I apply this other template for only certain pages and the rest just default to page.tpl.php?
Thanks! I am on Drupal 6.
In Drupal the templates follow so called "suggestions".
For pages, suggestions are built up using the url-path.
On page /foo/bar you can name your page.tpl.php
as follows:
Drupal will look from most specific to least specific and pick the first one found. If page-foo-bar.tpl.php is found, it will use that for foo/bar if not found it will look on. If then it finds page-foo, it will use that.
page-foo.tpl.php will also be used for /foo/beserk foo/pirate and foo/parrot, unless off course, you create a page-foo-parrot.tpl.php.
The front-page has no path (obviously) but a suggestion for the fron-page does exist: page-front.tpl.php
will be used only for the frontpage.
In addition to Drupal's default suggestion system, you can implement template_preprocess_page in your theme and change the template suggestion array:
function my_theme_preprocess_page(&$vars) {
if ($vars['some_var'] == 'some_value') {
$vars['template_files'][] = "page-special";
}
}
See Working with template suggestions.
You can also force the template file rather than adding a suggestion:
function my_theme_preprocess_page(&$vars) {
if ($vars['some_var'] == 'some_value') {
$vars['template_file'] = "page-special";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With