PHPTemplate is the theme engine that was used in Drupal from version 4.7 up until Drupal 8.x. In layman’s terms, a theme engine is what is used to run the code in the templates.

It’s a way of outputting PHP in HTML, without having to use PHP syntax or PHP tags.

This ultimately leads to code separation and allows easier styling, even for those who aren’t proficient in PHP.

Brief History

PHPTemplate was built by developer Adrian Rossouw specifically for use with Drupal. It was included in Drupal versions 5 and up, however, specifying the theme engine was still required in the .info file.

In Drupal version 7, it was no longer needed and the PHPTemplate engine was established as the default.

However, in 2012, with Drupal version 8, a new templating engine — Twig –was introduced. Twig replaced PHPTemplate.

The main reason for the change was the fact that many people struggled with using the PHPTemplate system. Plus, with Drupal 8, developers wanted to shift to object-oriented PHP instead of procedural PHP, which was the standard of previous versions.

Need Web Hosting?

If you're launching a new site or just looking for a new web host, check out one of our top hosting providers:

Developers say Twig makes it easier to work with themes in Drupal.


Twig marks a new era when it comes to Drupal templating engines. It works by compiling templates down to plain optimized PHP code and has a sandbox mode to evaluate template code.

It was created by Fabian Potencier, the creator of the Symfony framework, and is released under the BSD license.

Aside from being used in Drupal 8, it also powers projects like Symfony, eZ Publish, phpBB, Piwik, OroCRM, and more.

How PHPTemplate Works

Drupal’s core installation includes a variety of folders containing different files necessary for it to work.

One of those folders was called PHPTemplate. It contained phptemplate.engine, which was responsible for parsing the PHP variables in various template files.

The phptemplate.engine file contained two hooks: hook_init() and hook_theme(). Together, those two hooks called the necessary files such as CSS and JS as well as registered the theme’s functions and templates that were used in the theme.

The only file necessary for the theme engine to work was the page.tpl.php file.

Some themes used only the basic version of this file, while others employed a wide variety of additional template files that style specific content or screen space.

PHPTemplate Alternatives

Several template engines exist for Drupal and have been used in some themes, although not as much as PHPTemplate, which was the most popular one for a long time.

The most notable ones include:

  • Smarty: Like PHPTemplate, Smarty facilitates the separation of presentation from application logic but uses a much simpler syntax and compiles copies of the templates as PHP scripts. This allows developers to have the benefits of both the template tag system and the speed of PHP.
  • PHPTal: Another engine that uses a much simpler syntax and moves the presentation into the (X)HTML attributes rather than using tags.

Current Status of PHPTemplate

Since the introduction of Twig in Drupal 8, PHPTemplate has been minimally maintained.

Drupal states that PHPTemplate has “problematic security” and advises: “Don’t use it unless you know what you are doing and are prepared to implement your own text sanitization.”


The following list of resources includes tutorials, videos, and books dealing with PHPTemplate.

Online Resources

Here is a collection of articles and tutorials explaining the basics of the PHPTemplate engine and its replacement, Twig.

Video Tutorials

This is a small collection of video tutorials with practical examples geared for visual learners.

  • Preparing for Drupal 8: A series of video tutorials designed to make the transition from Drupal 7 to 8 as easy as possible with an explanation of why PHPTemplate was replaced and how the new engine, Twig, works.
  • PHP for Themers: A series of video tutorials dedicated to using the PHPTemplate engine and creating themes for Drupal 7.


Although no book deals specifically with the PHPTemplate engine, several related books have whole chapters dedicated to it with the aim of helping you master theme and module development.

  • Drupal 5 Themes (2007) by Ric Shreves: This book about creating themes for Drupal 5 has a chapter dedicated to the PHPTemplate engine and goes into great detail explaining how it works with practical examples.
  • The Definitive Guide to Drupal 7 (2011) by Melancon, et al: A thorough guide to Drupal 7 with a detailed chapter on PHPTemplate and using it to create themes.
  • Learning Drupal 6 Module Development (2008) by Matt Butcher: This book provides a practical hands-on approach to developing custom Drupal modules with a strong focus on themes using the PHPTemplate engine.

Moving on From PHPTemplate

PHPTemplate allowed Drupal developers to create very powerful themes which could (and often did) completely override the functionality of basic templates.

It allowed for a complete separation of logic and design and gave experienced developers a way to create custom functionality for the needs of their themes.

By using the resources above, you should become familiar with PHPTemplate and learn how to move forward in development, with or without it.

Further Reading and Resources

We have more guides, tutorials, and infographics related to website development and management:


Ultimate Guide to Web Hosting

Check out our Ultimate Guide to Web Hosting. It will explain everything you need to know in order to make an informed choice.

Compare Popular Web Hosting Plans

Need a great web host? Want to save some time? This shortlist is your best place to begin:

  1. Popular Host Choice for 2022
    Starting at $2.75/mo View Current Deal
  2. Starting at $3.99/mo View Current Deal
  3. Starting at $20/mo View Current Deal
  4. GreenGeeks logo


    Starting at $2.49/mo View Current Deal
  5. HostGator Square Logo Cropped


    Starting at $2.64/mo View Current Deal
  6. Starting at $2.99/mo View Current Deal

Browse Web Hosting Provider Reviews