LiipThemeBundle icon indicating copy to clipboard operation
LiipThemeBundle copied to clipboard

Using several themes in the same process

Open stof opened this issue 11 years ago • 6 comments

Currently, it is not possible to use the same template in different themes in the same PHP process, because the Twig_Loader_Filesystem caches the resolution of template names to file names in memory. Fixing this would require replacing the Filesystem loader with a theme-aware version (it would also be required for #50 btw).

My use case for rendering the template in different themes int he same process is background processing: I select the theme based on the user in my app. The background process sending them emails should also use the right theme. But the process can send emails to users with different themes. Not being able to change the theme is already an issue when doing it in a command, but it becomes even worse when the logic is in a RabbitMQ consumer (as the process is long-running).

As I need it at work, I will look into implementing it.

stof avatar Jun 19 '13 09:06 stof

I guess this might also enable referencing a non themed template from the themed template with the same "name"

lsmith77 avatar Jun 20 '13 09:06 lsmith77

it would require defining a specific naming convention for this

stof avatar Jun 20 '13 10:06 stof

Any update on this as this looks very interesting.

yellow1912 avatar Oct 19 '13 10:10 yellow1912

I also need this functionality, and so took a quick look at implementing it.

Apologies if I have missed something, but this seems as though it can be solved relatively simply by using a custom Twig filesystem loader, as stof suggested. This solution does not solve the 'referencing a non-themed template from a themed template' issue.

Here's the proof of concept: c501b2da4d6c67e591ee332bd3e8a8393a7eed35. Please excuse any code formatting issues - if this solution has any legs I'll tidy it up and submit a PR.

Suggestions are welcome.

xanido avatar Feb 09 '15 04:02 xanido

its always easier to review code in a PR .. so open up the PR and we can discuss. note you can update a PR by simply pushing to your branch as often as you want.

lsmith77 avatar Feb 09 '15 07:02 lsmith77

Done. See liip/LiipThemeBundle#116. Cheers.

xanido avatar Feb 09 '15 21:02 xanido