Twig is a modern, optimized template engine for the PHP programming language developed by Fabien Potencier. It is an open source product licensed under a BSD License, initially created by Armin Ronacher. Due to its uncomplicated syntax and straightforward processes, Twig is a widely praised template engine in the PHP community.
Fabien Pontencier discovered Twig as he was looking for a PHP template language. He continued Ronachers work, who wrote it back in ’08 for a blogging platform but stopped developing it to pursue working with Python. While developing Twig, Pontencier wrote a documentation about it and created a website for it.
But why is Twig so Highly Praised?Twig is fast, it complies templates down to plain PHP. Thereby Twig reduces the amount of PHP overhead to a very minimum, producing a faster, smoother user experience.
Twig is very concise compared to the PHP language leading to a more readable templates.
Supported by its flexible lexer and pars
er, Twig is very extensive. Making it possible for the developer to devise his own custom tags and filters. Further it allows to create its own DSL. All thanks to an open architecture.
Twig doesn’t conserve in view of security, giving the user some unique features. You can now activate automatic output escaping globally or for a block code, just to be sure. Furthermore, Twig has a sandbox mode which enables you to verify any untrusted code. Resulting in the possibility to use Twig as a template language for applications and still using it to modify the template design.
In addition, Twig offers abbreviations for common patterns, like displaying a default text when you go over an empty array.
Twig is also full featured. Which means it supports all you need to build templates with ease. For example: blocks, automatic output-escaping, multiple inheritance and more. But although being so full featured, Twig is still the fastest PHP template engine.
|Library||Time(sec)||Memory(Ko)||Templates rendered per second|
Plus Twig consumes less memory:
|Library||Memory without compilation (Ko)|