When we think about PHP Template Engine, the most famous library is certainly Smarty. However, we may consider other alternatives to Smarty. In this post we have collected 16 template engines written in PHP that allow you to separate HTML code from PHP code.
In the comparison table below, we have included:
- latest version (stable or beta) of library
- PHP version required
- size of zip package
- library extensibility
- forum or group where users can ask for help
|Open Power Template||2.0.6||5||1.30Mb||No||Yes||Yes|
PHP Template Engines
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. This implies that PHP code is application logic, and is separated from the presentation.
The Smarty design was largely driven by these goals:
- clean separation of presentation from application code
- PHP backend, Smarty template frontend
- compliment PHP, not replace it
- fast development/deployment for programmers and designers
- quick and easy to maintain
- syntax easy to understand, no PHP knowledge required
- flexibility for custom development
- security: insulation from PHP
- free, open source
Savant is a powerful but lightweight object-oriented template system for PHP.
Unlike other template systems, Savant by default does not compile your templates into PHP; instead, it uses PHP itself as its template language so you don’t need to learn a new markup system.
Why Use Savant for Templates?
- You don’t need to learn a new language or markup to create a template. The template language is PHP, and the template file is a regular PHP file.
- You don’t have to worry about separate directories (or permissions on those directories) for compiled template sources, because Savant is not a compiling engine (the template scripts are already written in PHP).
- Even though Savant is not itself a compiling system, you can write your own compiler and plug it into Savant; this means you can use any template markup system you like.
- The Savant source code is easy to read, understand, and extend, because it is exceptionally well-commented.
- The object-oriented plugin, filter, error, and compiler classes for Savant are easy to use, understand, and extend.
- Because your template script is a regular PHP script, you can sprinkle it with comments and use phpDocumentor to document it.
PHPTAL is a templating engine for PHP5 that implements brilliant Zope Page Templates syntax. PHPTAL is a PHP implementation of ZPT work. To be short, PHPTAL is a XML/XHTML template library for PHP.
While most web developpers continue to use ASP/JSP/PHP tags as the core language of their templates, the Zope community came with a refreshing idea named TAL. The idea was to move presentation actions inside XHTML attributes instead of using plain tags or elements.
Some PHPTAL advantages and features:
- enforces the separation between logic and presentation (the holy grail),
- warns you if you forget to close an HTML tag or have syntax errors in your template,
- no more
- quite clean and readable templates,
- ability to insert sample text inside template to preview template result without PHP backend,
- integrates quite well with WYSIWYG HTML editors,
- data abstraction using XPath-like system,
- cool HTML macro system,
- integrated internationalization system (using
gettextor your own backend),
- ability to replace XPath-like system with PHP expressions,
- nearly no speed loss (templates are compiled, expensive expressions can be replaced with plain PHP).
- compatible with PHP accelerators, which can improve performance even further,
- more than four years of ZPT community support (see zope website),
- extensible and easily hackable code,
- makes good use of PHP5 and SPL.
TinyButStrong is a library that enables you to dynamically create XML/HTML pages and any other files based on text source. It’s a Template Engine for the PHP language. It enables you to easily display information from your database, but also to seriously harmonize and simplify your PHP programming.
TinyButStrong is oriented to HTML but not specialized to Html. This means it can work as well with Text files, XML, RSS, RTF, WML, Excel (xml), … The OpenTBS plug-in enables your to merge OpenOffice and Ms Office documents.
- can connect to any database type (in native: MySql, SQLite, PostgreSQL),
- easy date-time and numeric formats,
- blocks with alternated display,
- multi-columns display,
- conditional display,
- event functions,
- file inclusion and other scripts execution,
- cache system,
Yapter (Yet Another PHP Template Engine (r)) is a simple, yet powerful template engine written completely in PHP, for PHP. Its purpose is to fully strip programming logic from the graphical aspects of creating websites in an elegant way.
Dwoo is a PHP5 template engine which is (almost) fully compatible with Smarty templates and plugins, but is written from scratch for PHP5, and adds many features.
- Template Inheritance, a fresh look at complex template structures, now built without includes
- Sub-template declaration within templates to allow recursive templates.
- Smarty syntax compatibility with several additions and shortcuts to speed up template writing
- Flexible plugin creation, plugins can be wrapped in classes or simple functions, they can be precompiled to optimize the load time of the template, etc.
- Scope aware engine, allowing for shorter templates
- Unicode / UTF-8 support for string manipulation functions.
- Generally faster than Smarty with variable speed improvements depending on the features used.
- E_STRICT compliant code that does not throw PHP warnings.
- Ready to use with several frameworks using the provided adapters (ZendFramework, Agavi, CakePHP, CodeIgniter)
QuickSkin is a Template Engine that was designed to support web based applications of any size. It is particularly suited to large scale applications like Content Management Systems. The project was originally started by Philipp v. Criegern and named “SmartTemplate”. The project was then taken over by Manuel ‘EndelWar’ Dalla Lana and HonestQiao. The name of the project back then led to confusion with Smarty Templating. Despite its advantages over other templating systems (speed, small footprint, ease of use, power), SmartTemplate has not been updated and had many outstanding bugs. Worx International Inc. has been using SmartTemplate on a variety of projects for several years. Over that time we have become very familiar with the code. We have now taken over the project. Our first task was to rename the project to make it less confusing, fix the bugs, and extend its capabilities — while maintaining its core simplicity and ease of use.
- Simple Scalar Substitution (Strings, etc.)
- Block Iterations (nested Arrays / BEGIN..END)
- Basic Control Structures (IF..ELSEIF..ELSE)
- Custom Extension (Output filters, uppercase, sprintf, etc.)
- Template Compilation (HTML templates are converted to executable PHP Code)
- Output Caching (Accelerates your applications by reusing page output)
- November 2007: QuickSkin is now PHP5 compliant and tested up to and including PHP 5.2.4. It is not tested with E_STRICT. One package to support both PHP4 and PHP5.
RainTPL is an open source PHP template engine, it load precompiled PHP templates:
- Easy, 8 Tags, 3 Methods, 1 Class in a single File
- Fast, load precompiled templates
- Useful, divide logic by design
- WYSIWYG, design HTML with img/css with relative paths, Rain will substitute with the correct paths
FXL Template an easy to use template engine covering all the basic features of a template system. It supports simple text/array assignments, blocks and nested blocks. Well- used regular expressions and the simple markup are responsible for quick rendering. The template markup is really easy to learn – even for people not into programming. Everything can be done with just two types of place holders. For high traffic enviroments you are invited to test our “memcached” cache extension.
Sugar is a new template engine for PHP, similar in spirit to Smarty.
A powerful and flexible compilation engine is used which allows for powerful expressions similar to that of PHP itself. It also features a clean and easy to understand syntax, which was created with the average designer in mind.
Blitz is a templating engine with two main features:
- Fast. Blitz is written in C and built as PHP-extension which makes it one of the fastest template engines (you may see the benchmarks section below)
- Clear. Blitz has quite simple and clear syntax and makes developer to build compact and easy-to-read-and-support code even for applications with very complex presentation logic
Template Blocks is a visual template engine, replacing any semantics of previous generation engines with an AJAX interface.
It’s written in PHP and is distributed under the GPL.
PHP XTemplate is a cool templating engine for PHP. XTemplate allows you to store your HTML code separately from your PHP code (as opposed to compiling your template into PHP as per Smarty etc.). It has many useful features such as nested blocks and various kinds of variable interpolation, and yet the code is very short and very optimized.
Vemplator is PHP template engine that strives to be light-weight yet featured, and does quite well in only 200 lines of code. The template syntax is concise, and the code is written to be extensible.
Open Power Template
Open Power Template is a template engine for PHP5. Its task is to produce a full HTML code from the script data and ”code templates” that show, how and where put them. OPT has many features not only for programmers, but also for template writers that make this process nice and easy.
- Built-in XML parser that understands the HTML code structure and makes a real use of this.
- Scalable XML standard compliance – from the strict following the standards to the quirks mode ideal for processing non-XML documents.
- Modern and powerful template language that is something more that just a copy of control structures from PHP with modified syntax.
- Advanced support for declarative programming – tell, what you want to see, not how it is supposed to work.
- Imperative flow-control structures like loops and conditions.
- Sections – an advanced tool for constructing various types of lists, including tree rendering and displaying the data in columns.
- A set of tools for template modularization: inclusions and template inheritance (even dynamic).
- Blocks – easy-to-write instructions evaluated at runtime.
- Components – creating HTML forms with templates never was so easy.
- Smart HTML escaping and XSS filtering syntax techniques.
- Tools for code reuse – write once, use everywhere.
- Template portability – the same template code runs correctly in different places and with different data formats.
- Powerful expression engine with support for PHP objects.
- Large function set.
- Support for multilingual websites.
H2o is template engine for PHP, there are a lot of the concept are inspired by projects like Django templates, Smarty and Jinja, implemented in a way that makes sense in PHP.
- Readable and natural syntax.
- Reuse template inclusion and inheritance.
- Extensible through filters, tags and template extensions.
- Battery included – bundled rich set of filters and tags
- Various caching support with multiple back-end
TPLN is a fast php template engine.
The PHP code is separated of your design what facilitates the update of the design of your documents and to permit to separate work between webdesigner and PHP coder your work is built faster and it is easier to update !
- Extremely easy to learn
- Open source project
- Powerful Plugin system (DB Pager, Captcha, Forms, Cache, Rss, Mail, Image)
- Database Abstraction layer via PDO (MySQL, Oracle, SQL Server…)
- Full Documentation, Friendly Community, …