title: Twig (in Symfony) : access template parameters from twig extensions
body: <p>I would like to access Twig template parameters from my twig extensions (filters, functions...) without passing it explicitly.</p>
  
  <p>I always need a "displayPreferences" variable in all my twig extensions, in order to change the way to display and transform values.</p>
  
  <p>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.</p>
  
  <p>Something like that would be great:</p>
  
  <pre><code>/**
   * 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-&gt;accessTemplateParameter('displayPreferences');
  
      switch ($renderPreference['dateFormat']) {
          // Do something
      }
  }
  </code></pre>