Home » , » Symfony 2.7 – A New Feature 'Twig' as a First-Class Citizen

Symfony 2.7 – A New Feature 'Twig' as a First-Class Citizen

jaki watson | 22:49 | 0 comments
Symfony Development
Many of you all may have used Symfony2 and experienced that the platform did not support Twig. But the company's professionals work hard on developing a new template language Twig that mainly based on the Python Jinja2 language.

Now, Symfony2 became the first popular framework that adopted a non-PHP templating engine in core. While developing, the professionals had no idea that it would become a highly popular choice among Symfony developers. Finally, Symfony2 allows people to use both PHP and Twig in their applications.

Now, it is clear that Symfony2 has won the heart of a lot of Symfony2 and PHP developers, and Twig is also used by a lot of open-source CMSes along with Symfony. Now, you will surely think that what's the mean of Twig as a First-Class Citizen in Symfony2?

The company has added an abstraction layer to make it capable of supporting PHP and Twig. When it comes to taking it as a developer, you will mostly interact with this abstraction through the templating service which enables one application to use PHP and Twig. However, you can also imagine that this abstraction will add a layer of complexness, and it also offers some of the performance impact.

The company would like to extract the Templating component into an independent library for Symfony 3.0, but many of you all may want Twig as a front and center in the framework. However, the good news is that the work has been done in Symfony 2.7.

Want to Use Twig in Symfony 2.6?

If you are looking forward to using Twig in Symfony 2.6, you cannot use Twig directly as you need to use the templating sub-system through the templating service. Moreover, some of the Twig extensions are depending on PHP helpers as the PHP templating system is always loaded even if it is not configured in the templating engine's option.

The minimal code you can write to render a Twig template reads as follows:



You can have a look that the Twig bundle has been allowed, and the templating engines sets Twig as the only engine.

Make Use of Twig Without the Templating sub-system:

The templating configuration can be removed entirely as of Symfony 2.7 and Twig can be used directly:



Some disadvantages of Using Twig Directly

Users are not allowed to use some base controller class shortcuts (likerender() orrenderResponse()), the web profiler does not display the time as it took to render templates anymore, the “@bundle” writing can't be used when referencing templates. However, all these problems will be fixed in the coming weeks.

Stay connected with us to get more information on Symfony and its solutions as here we will give latest and top stories of Symfony. Moreover, you can also get support from Symfony developer to discuss your issue or project.
Share this article :

0 comments:

Post a Comment

 
Design by: