I need to pass variables to template from two places:
-
Normal controller’s method, eg:
class ProductsController extends Controller { /** * Products * @Route("", name="products") * @Template */ public function productsAction() { return array('var1' => 'sth', 'var2' => 'etc); } -
Bootstrap controller (listener triggered by kernel.controller event)
class BeforeControllerListener { public function onKernelController(FilterControllerEvent $event) { // @some_vars }
How can I inject @some_vars from listener to template? Vars in both methods aren’t static, so global variables aren’t the answer.
In your
onKernelController()do:In your
productsAction()do:Cheers 😉