My question is similar to this question but slightly different and since that question wasn't answered, I thought I would try again.
I know Symfony will look first in app/Resources/FooBundle/views
and then second in FooBundle/Resources/views
for templates. I would like to "inject" another location between the two, e.g.
app/Resources/FooBundle/views
BarBundle/Resources/FooBundle/views
FooBundle/Resources/views
I've tried overriding the \Symfony\Component\HttpKernel\Config\FileLocator
service and added a path there, but this didn't work. I've also tried the answer here in the controller::render method without success. (the 'native' method suggested there doesn't work because the path comes from a dynamic setting.)
As a secondary note, I need to be able to add this path later (maybe onRequest) instead of at container creation. So an EventListener, custom service method or call in the controller would be appropriate.
Part of the challenge in solving this problem was realizing that (at least in Symfony 2.7) there are at least two ways to specify a template name: the 'old way' (for lack of a better name) and the 'name-spaced' method which was implemented later. e.g.
These two methods result in different template location searches and therefore code had to be modified in two different places.
In order to modify the 'old' way, I overrode the Kernel::locateResource() method
In order to modify the namespace way, I added a ControllerListener
I hope this helps anyone coming along looking for a similar solution.