I'm using a file serving as a form layout to overwrite certain elements (form_start, form_row, etc.). I register it like:
twig:
- AcmeMainBundle:Form:formlayout.html.twig
Is there a way to use in it my variables provided along with a form?
For example, when I send to index.html.twig
array ('form' => $formView, 'var' => $var);
Var is defined only in index.html.twig.
So how to make var defined in formlayout.html.twig
To set a global variable in Twig I created a service call "@get_available_languages" (return an array) and then on my kernel.request event class I implemented the below:
Hope that helps
Peace
You can use
addGlobal()
method.For example in BaseController I use:
so in your case you should probably do:
In case you don't use symphony but use twig on it's own, it is as simple as: