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.
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.
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.
phptemplate.engine file contained two hooks:
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
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.
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.
Here is a collection of articles and tutorials explaining the basics of the PHPTemplate engine and its replacement, Twig.
- Open Discussion on Drupal’s Theming Capabilities and Templating Engines: Older resource that includes thoughts from PHPTemplate’s developer on why he created it and the functionality he planned to include.
- Building a New Theme for Drupal 7: An in-depth tutorial that explains how the theme engine works and guides the user through the necessary steps to creating a working theme for Drupal 7.
- PHPTemplate: Official Drupal page with release history.
- Templating Engines in PHP: An article by Twig’s author that outlines why PHPTemplate is not a good choice as a templating engine and how Twig came about.
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:
Drupaler looking for a great deal on hosting?
A2 Hosting scored #1 in our recent speed and performance tests. They support Drupal and provide free site migration. Save up to 50% on their dev-friendly plans by using this discount link.
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.