cakephp / twig-view

Twig View for CakePHP
MIT License
13 stars 6 forks source link

Static Twig environment issue #72

Closed robertpustulka closed 3 years ago

robertpustulka commented 3 years ago

Is there any reason the Twig\Environment is a static property in the TwigView?

This creates an issue where for example we have differently configured environments for an app view and a mailer view. Once the environment for an app view is set up it is then reused in a mailer view even if the environment config is different.

ADmad commented 3 years ago

https://github.com/cakephp/twig-view/blob/07c7f8b44beac77310f358f76596d5f5a9432c2f/src/View/TwigView.php#L104

That's the reason.

robertpustulka commented 3 years ago

Maybe the instances should be cached based on the config? The environment config array can have a hash generated and be stored with that key.

othercorey commented 3 years ago

Can you give an example of a difference in the environment?

robertpustulka commented 3 years ago

@othercorey sorry for the late response. I have different twig based views for a UI and for mailers in my app. Eventually I figured out how to use the same twig instance for both, so for my use case the issue is "resolved" :).