Written by Matt Caprioli, Content Marketer at eZ
Twig

Twig is a modern PHP template engine developed by SensioLabs. One of the most widely praised template engines in the PHP community, Twig is driven by hundreds of contributions and continues to grow along with the Symfony project.  

Built in 2009 by Fabien Potencier, the creator of the Symfony framework, Twig helps front-end developers and designers create templates with relative ease. Twig compiles templates down to plain optimized PHP code to obtain good performance, and there are optional PHP modules to accelerate its performance further. For security, it also provides a sandbox for assessing template code, and is backed by a lexer and parser, enabling developers to define custom tags and filters.

A component of the Symfony full-stack framework, Twig is system-agnostic. Developers can build Twig templates for the front-end of a site or app, share the designs with the customer, and gather feedback and optimize the templates, all before a PHP-based system, like a CMS, is selected. More and more PHP-based systems, including CMS systems like eZ, are using Twig for its security, speed and flexibility.

"Twig is very popular for developers, its modular and very flexible," said Marco Luedtke, Managing Partner at the Web Agency umwerk GmbH, which used Twig for a recent eZ project for Marquardt Küche, a luxury kitchen supplier in Germany.

eZ welcomes Symfony developers

Our commitment to the Symfony full-stack framework has many benefits for Symfony developers who want to build content-driven sites and apps. eZ adopted the Symfony framework in 2012 and our new open source core, eZ Platform, like its predecessor eZ Publish 5.4, is also based on the full-stack framework.

Beginning with eZ Platform 15.12 ("1.0"), our CMS now follows Symfony standard distribution more closely with the same directory layout to make sure all Symfony documentation applies to eZ without any differences, making it easier for beginners to get started.

As eZ Platform evolves in 2016 and beyond, developing in eZ will be like developing in Symfony, with the same language, PHP, the same library for deployment and version dependency, Composer, and the same templating system, Twig.

Symfony developers will already know how to make the most out of Twig and we’ve provided documentation on 10 specific Twig functions for eZ Platform. Developers who aren’t familiar with Symfony will likely have some understanding of Twig, if they’ve used other text-based template languages such as Django, Jinja and Smarty, which eZ used previously for eZ Publish.

How we use Twig for our own sites

eZ’s microsites for eZ Platform, eZ Studio and eZ Conference all use Twig, and we will be migrating this very site, ez.no, completely to the Symfony full-stack framework soon. In each case, using Twig helped us design templates fast.

"It’s really easy to learn Twig because you don’t have many functions, and the base is HTML," said eZ Product Manager Sylvain Guittard, who developed all three microsites together with the eZ Engineering Web Team. "So if you know HTML, you just need a few more functions and you’re good to go."

For the eZ Conference site, Sylvain built his own controller to retrieve content from the repository, created a request to call content from the conference program, and the Twig template took care of the rest, including the organization of the content and the design of the front end. Here's a piece of the template and what's rendered on the front end of the site.

Twig sample code

How are your front-end developers using Twig? Share your comments below.


Further reading on Twig:

eZ Twig functions
Twig quick start
Twig content rendering with eZObjectWrapperBundle

Load Comments
loading...