In order for a content type to use a different page template in drupal 7 you need to do two things.

  • Create a new page template using the right naming convention
  • Add the new template file to the theme_hook_suggestions in your theme’s page preprocess

1. New Page Template file

Lets say you have a new content type called course_quiz. The right way to name your new page template file would be: page–course-quiz.tpl.php . Just copy the content from your theme’s page.tpl.php and make your modifications.

2. Add to theme hook suggestions

  • Add the following code to your themes template.php file.
  • Rename YOURTHEME to your own themes name.
  • Change course_quiz to the name of your own content type, everywhere you see it in the code.

.

<?php

/*
 * bit.ly/developermug
 */

function YOUTHEME_preprocess_page(&$variables) {

  if (!empty($variables['node']->type)) {
    if ($variables['node']->type == 'course_quiz') {
      $variables['theme_hook_suggestions'][] = 'page__course_quiz';
    }
  }

// Create page--course-quiz.tpl.php from page.tpl.php
// and add custom markup there
// course_quiz content type will now use that file
// dont forget to clear cache
// lehelmatyus.com

?>

.

3. Don’t forget to clear cache
I have a glass coffee mug that says that. I etch glass mugs in my spare time. Let me know if you want one at Coffee Mugs for Developers.

4. Have a beer, you are done

 

Your feedback is appreciated.
Thanks