Custom page.tpl.php Template

How do you create a custom page template based on content type for a Drupal 7 site? Simply start from the page.tpl.php, the Drupal default page template. The process of creating a custom page template involves:

  1. Renaming the template file
  2. Creating a pre-processor function
  3. Clearing cache

Renaming the template file

In this step, you add the machine name of the content type to the file name i.e. page.tpl.php:


Create Pre-processor Function

This function is placed in template.php as follows:

function themename_preprocess_page(&$vars, $hook) {
if (isset($vars[‘node’]->type) && !empty($vars[‘node’]->type) && ($vars[‘node’]->type == ‘content_type_machine_name’)) {

$vars[‘theme_hook_suggestions’][] = ‘page__’ . $vars[‘node’]->type;

Replace the ‘themename‘ and ‘content_type_machine_name ‘with your own values i.e. the name of your theme and the content type respectively.

Clear Cache

Clear cache under admin/config/development/performance to allow for the reloading of template file.

Please follow and like us:

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

April 23, 2014

Posted In: Information Technology

Tags: ,

Leave a Comment