I would like to access Twig template parameters from my twig extensions (filters, functions...) without passing it explicitly.
I always need a "displayPreferences" variable in all my twig extensions, in order to change the way to display and transform values.
It is possible to pass this variable as a template parameter, and pass it as an argument for each Twig filters / functions I run, but that makes the templates difficult to read.
Something like that would be great:
/**
* Twig filter (render a date using the user defined format)
*
* @param Date $date
*/
public function renderUserDate ($date) {
// Somehow, get a template parameter, without receiving it as argument
$renderPreference = $this->accessTemplateParameter('displayPreferences');
switch ($renderPreference['dateFormat']) {
// Do something
}
}