Overriding Page Templates per Content Type in Drupal 7

As we know drupal have few  template files: html.tpl.php, page.tpl.php and node.tpl.php. There are few more which controlling the display of more specific elements . For overrriding other templates you may search more now let me show you how to override the page tempates per content type.

We can implement it by adding additional tempalte suggestions to the “theme_hook_suggestions” array in template.php

  1. Open the template.php file in your theme for editing.
  2. Look for a function called yourthemename_preprocess_page (replace the yourthemename with your theme’s name).
  3. If this function already exists, you will need to add the if statement to the end of the function just before the closing bracket. Otherwise you’ll need to create a new function to look like this:

function yourthemename_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;

Now you can create a template file called page–content-type.tpl.php and all nodes with that type will use the new template file.

Filename Notes:

  • Use two dashes after the word ‘page’ in the filename.
  • If your content type is two or more words, replace the underscore ( _ ) with a short dash ( – ) in the content type machine name.

6 thoughts on “”

  1. Magnificent publish, very informative. I ponder why the other specialists of this sector don’t notice this. You should continue your writing. I’m sure, you have a huge readers’ base already!|What’s Taking place i’m new to this, I stumbled upon this I have discovered It positively helpful and it has aided me out loads. I’m hoping to give a contribution & aid different customers like its helped me. Good job.

  2. Hello there, I found your web site by way of Google whilst searching for a comparable matter,
    your site got here up, it appears great.
    I have bookmarked it in my google bookmarks.
    Hello there, just was alert to your weblog through Google, and located
    that it’s really informative. I’m gonna be careful for brussels.
    I’ll appreciate should you continue this in future. A lot of folks will likely be benefited from your writing. Cheers!

    1. I am not author for all the post in this blog. All I meant to share something cool and may be useful for people

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s