Is there a possibility to extend a Twig template with a PHP template?

In some project I have a big Twig base template, but for the content section of some sub-layouts I have to extend it with plain PHP templates (for flexibility). Is there any possibility to do that?

Example: layout.html.twig base template should be extendend with Content/complexLayout.html.php


You need to enable PHP and Twig engine and try if using $this->extend(‘layout.html.twig’) in your PHP template works.
But i think mixing it is not a good idea :slight_smile:

1 Like

extending twig templates with php and vice versa is not possible.



I thought so. But never tried it.

Thanks for clarifying!

Extending Twig with PHP, even if possible, is not a good idea. Mixing templates is not encouraged nor recommended. Symfony will deprecate PHP templates in the next version, so there’s no need for that anyway.

Do you think using Twig-Templates will become mandatory in future versions of Pimcore? (

Most definitely, in my opinion. As stated here:

Deprecated since version 4.3:The integration of the Templating component in FrameworkBundle has been deprecated since version 4.3 and will be removed in 5.0. PHP templates will no longer be supported and you’ll need to use Twig instead.

Since Pimcore in its current form relies on Symfony (it IS a Symfony-based application, after all), unless they move away from the framework (which I doubt, since I bet the transition from Zend has been painful, to say the least, and Symfony has a HUGE community), they will be forced to abandon PHP templating in future releases completely.

Regarding Symfonys policy of such a move, I think it’s completely understandable, since Twig is easier to develop in (for front-end devs at least). And you get an added bonus of completely removing the backend logic from frontend, since all the relevant code remains in the controller. With a PHP template, inexperienced devs easily fall into the trap of making backend changes in the template which should never be the case.