Page templates in Zen-based sub-themes

Dev

Page templates in Zen-based sub-themes

by Sean Corrales

One of the nice things about theming in Drupal is the ease of overriding items when theming. For example, if you wanted to drastically alter the HTML of the pages for certain content types, you could do so with overrides like page-content_type.tpl.php. However, a lot of themes don’t have support for this out of the box including the popular Zen theme and sub-theme.

Here’s a code snippet from Drupal.org that does the job. I can’t take the credit for writing it; that belongs to Drupal member khonggiannet. Just paste this into the template.php in your theme and you’re ready to go.

Here’s the the code:

/**
 *
 * Override templates using page-[content-type-name].tpl.php
 * From http://drupal.org/node/223440
 *    
 */

function themename_preprocess_page(&$variables) {
  if ($variables['node']->type != "") {
    $variables['template_files'][] = "page-" . $variables['node']->type;
  }
}

More About the Author

Sean Corrales

Lead Web Developer
Internet Explorer ignoring CSS files Like most web developers, I do most of my development work in one browser (in my case, Firefox) and then do cross browser checks after ...
Creating checkout panes for Ubercart All code comes from a shipping insurance module I wrote for Ubercart. I plan to release it on ubercart.org and drupal.org after I ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072