title: Symfony2 Circular reference
body: <p>Probably I have a problem with a loop in template.</p>
  
  <pre><code>services:
      twig_menu:
          class: Cms\PageBundle\Twig\Menu
          arguments: ['@doctrine.orm.entity_manager', "@templating"]
  </code></pre>
  
  <p>Code php:</p>
  
  <pre><code>namespace Cms\PageBundle\Twig;
  
  use Doctrine\ORM\EntityManager;
  use Symfony\Component\Templating\EngineInterface;
  class Menu {
      protected $em, $templating;
      public function __construct(EntityManager $em, EngineInterface $templating){
          $this-&gt;em = $em;
          $this-&gt;templating=$templating;
      }
      public function show($typ){
          $menu=$this-&gt;em-&gt;getRepository("CmsAdminBundle:Menu")-&gt;findBy(array('type_id'=&gt;$typ));
          return $this-&gt;templating-&gt;render("menu.html.twig", array('links'=&gt;$menu));
      }
  }
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>&lt;ul&gt;
      {% for link in links %}
          &lt;li&gt;&lt;a href="{{ link.href }}"&gt;{{ link.name }}&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>When I cleared cache on the first refresh it is ok, next I get this error:</p>
  
  <blockquote>
    <p>Circular reference detected for service "templating", path:
    "templating -> twig -> twig_menu".</p>
  </blockquote>