title: How to use custom Twig filters in Twig template rendered from string?
body: <p>I want to render Twig template from string (in fact from database but it doesn't matters) and method showed in this <a href="https://stackoverflow.com/a/11906647/845978">question</a> works fine. But I can't use my custom filters, defined in custom Twig extension, which works in templates rendered in standard way (from files).</p>
  
  <p>What should I do to allow string-templates use custom filters?</p>
  
  <p>I'm getting template from string in this way:</p>
  
  <pre><code>$env = new \Twig_Environment(new \Twig_Loader_String());
  echo $env-&gt;render(
    "Hello {{ name }}",
    array("name" =&gt; "World")
  );
  </code></pre>
  
  <p>I've found in <code>\Twig_Environment</code> class method <code>addFilter</code> but my filters are defined in Twig extension so I don't know if it's proper method to use.</p>
  
  <h2>Solution:</h2>
  
  <p>Thanks to <strong>Luceos</strong> comments I've solved my problem just by using existing Twig engine instead of creating new one. When I set Twig Environment this way:</p>
  
  <pre><code>$twig = clone $this-&gt;get('twig');
  $twig-&gt;setLoader(new \Twig_Loader_String());
  </code></pre>
  
  <p>then everything works as expected. (Solution found in <a href="http://www.techpunch.co.uk/development/render-string-twig-template-symfony2" rel="nofollow noreferrer">http://www.techpunch.co.uk/development/render-string-twig-template-symfony2</a>)</p>