title: Symfony2 Variable "name" does not exist
body: <p>I'm new to Symfony, so this is most certain a simple mistake from my side.</p>
  
  <p>I get the following error: Variable "worker" does not exist.</p>
  
  <p>The template looks like this:</p>
  
  <pre><code>{% extends "NTSBSServiceBundle::layout.html.twig" %}
  {% block body %}
  &lt;h1&gt;Rapportera&lt;/h1&gt;
      {% for worker in workers if workers %}
          {{ worker.name }}
      {% else %}
          &lt;em&gt;Det finns inga öppna protokoll för närvarande...&lt;/em&gt;
      {% endfor %}
  {% endblock %}
  </code></pre>
  
  <p>And the controller method look like this:</p>
  
  <pre><code>/**
   * List all open protocols, grouped by worker.
   * 
   * @Route("/", name="report")
   * @Method("GET")
   * @Template()
   */
  public function indexAction()
  {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
  
      $workers = $em-&gt;getRepository('NTSBSServiceBundle:Worker')-&gt;findAll();
  
      return array(
          'workers' =&gt; $workers,
      );
  
  }
  </code></pre>
  
  <p>I have checked, and $workers does contain entities from the database. The twig gets rendered. If I remove the for-loop, naturally the error message disappears.</p>
  
  <p>Hoping that someone can explain to me what I'm doing wrong.</p>
  
  <p>UPDATE:</p>
  
  <p>Have confirmed that the correct controller is used by exiting in indexAction(). If i do a print_r of $workers, I get the following output:</p>
  
  <pre><code>Array
  (
  [0] =&gt; NT\SBSServiceBundle\Entity\Worker Object
      (
          [id:NT\SBSServiceBundle\Entity\Worker:private] =&gt; 2
          [name:protected] =&gt; Worker 1
          [mail:protected] =&gt; worker1@example.com
          [phone:protected] =&gt; 123456789
      )
  
  [1] =&gt; NT\SBSServiceBundle\Entity\Worker Object
      (
          [id:NT\SBSServiceBundle\Entity\Worker:private] =&gt; 3
          [name:protected] =&gt; Worker 2
          [mail:protected] =&gt; worker2@example.com
          [phone:protected] =&gt; 123456789
      )
  )
  </code></pre>
  
  <p>Also I have tried to change the rendering-method by changing from annotation to using the render-method, as such:</p>
  
  <pre><code>return $this-&gt;render('NTSBSServiceBundle:Report:index.html.twig',array( 'workers' =&gt; $workers ));
  </code></pre>