New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Twig] Accept an array of template in the render method #29808

Closed
lyrixx opened this Issue Jan 7, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@lyrixx
Copy link
Member

lyrixx commented Jan 7, 2019

Description
Twig is able to select a template from an array of templates
(see https://github.com/twigphp/Twig/blob/735f266d72f253d59269f4cab38094070f3db22f/lib/Twig/Environment.php#L466 or https://twig.symfony.com/doc/2.x/functions/include.html )

I could be nice to expose this feature in the abstract controller. What do you think ?

Example

$this->render(['cms/layout/$layout.html.twig', 'cms/layout/default.html.twig'])
@mickaelandrieu

This comment has been minimized.

Copy link
Contributor

mickaelandrieu commented Jan 7, 2019

Hi,

it depends if you (ie the Symfony team) want to promote this practice or not... regarding what we do in the Grid component of PrestaShop (that initially relies on this nice feature), the impact on performances can be really big, so we manage to provide this a different way => https://github.com/PrestaShop/PrestaShop/blob/develop/src/PrestaShopBundle/Twig/Extension/GridExtension.php#L200

Also, outside of this scope, I've never met a use case for that when we already have so many ways to make templates dynamic, so I'm interested in your owns.

Mickaël

@lyrixx

This comment has been minimized.

Copy link
Member

lyrixx commented Jan 8, 2019

Actually, The response should be different according to the value of $layout (CSP-Headers).
So I finally added a real if ($template) in my controller.
I don't need this feature anymore.
I'm closing this issue as I think this is not a really common need

@lyrixx lyrixx closed this Jan 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment