title: Dynamic links in symfony2 based on a model
body: <p>How can I use a class (that is returned by a factory service) and one of it's methods to determine whether a link should be displayed or not?</p>
  
  <p>I could easily inject it via the <code>$this-&gt;render</code> method but it's a link used for several pages and I'd have to inject it to many controllers that use the same template manually.</p>
  
  <p>Is there another way I can access the factory in a twig template?</p>
  
  <p>The service I want to use looks something like this:</p>
  
  <pre><code>$factory = $this-&gt;get('somefactory');
  $model = $factory-&gt;build('somemodel', new SomeClass()); //SomeClass() is the first       parameter in $model's constructor
  $model-&gt;returnsABoolean(); //Determines if link should be showed or not.
  </code></pre>