New in Symfony 4.3: Deprecated the Templating component integration
April 30, 2019 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
The Symfony Templating component provides the tools needed to build any kind of template system, including the loading of template files from multiple sources, monitoring them for changes and using multiple engines to render them.
In Symfony applications this component allowed using both PHP and Twig to create the templates. However, nearly all developers use Twig to create traditional templates or use the serializer to output data. That's why in Symfony 4.3 we've decided to deprecate the integration of the Templating component in Symfony applications.
This means that, starting from Symfony 5.0, we will remove support for using PHP
templates and PHP form themes. You'll need to use Twig for those templates. In
addition to deprecating several classes, services and service tags, the
hinclude_default_template
configuration option has been moved to the
fragments
section:
1 2 3 4 5 6
# config/packages/framework.yaml
framework:
# ...
- templating:
+ fragments:
hinclude_default_template: hinclude.html.twig
Although the number of people using PHP templates in Symfony applications is minimal compared to Twig, if enough people would volunteer to work on an alternative solution, we'd consider the creation of a new PHPTemplateBundle that provides all the deprecated classes and support files. If you are willing to help, create an issue in the main Symfony GitHub repository to kick off the discussion around this.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
For example, in order to support view helpers, you would have to recreate the magic from Zend or just drop their usage. We also had bootstrap 3 forms (with decorators, etc), so we had to load that "magic" of Zend forms into Symfony.
Why in the world would you remove PHP templating from a PHP framework? That is just the dumbest thing I have heard of.
Not everyone uses Twig. Why would you hitch your wagon to something that could go away or be replaced by the next new thing? Something that is so clearly a debatable choice for a development team. Use Twig if you like it, but if not PHP is always there - always has been.
Help write a package to support PHP in a PHP framework? For my team, it would probably be easier to just use a different framework. One that is not so opinionated.
I think this is a really stupid idea and I am disappointed that such a clearly one-sided decision was made.
Apart from that, what you said about Symfony being an opinionated framework is simply not true. In fact, Symfony is by far the less opinionated PHP framework. You don't have to take my word for it. Just look around the other frameworks and you'll quickly come to the same conclusion.
For example, you can configure Symfony using PHP, YAML or XML (YAML is only used by default for convenience; but everything is configurable with PHP and XML too). Meanwhile, other frameworks dictate the format you have to use to configure them. That's what being opinionated is all about.
Does this now mean that we have to use render( controller( ... ) ) from within the Twig template every time? Every time I use this it feels wrong as I feel it undermines MVC principles.
@Justin - we first tried to do everything in PHP and eventually realised that it would have been a lot easier to just use Twig, so we made the decision to rewrite all the templates. It is hands down much better - give it a try, you won't regret it.
I get that maintaining support for different types of engines requires effort that could be put into other things, but would it be such a bad thing to leave the option open for people to add their own templating engine?
Where should I start and who can guide me through the process?
I really like Symfony, but I really don't want to learn a new language (twig) for me or my team.
As @Justin said, "Why in the world would you remove PHP templating from a PHP framework?"