title: Fetching data through a custom repository in a Twig extension
body: <p>I'd like to display new notifications on every page of my symfony 2 webapplication.
  I was advised to use a Twig Extension for this. I've created a function getFriendRequests in that extension, but I don't know if it's good practice to get data through my custom repository in the twig extension: Right now it's giving me the error, that it can't find the getDoctrine method. </p>
  
  <pre><code>&lt;?php
  
  namespace Tennisconnect\DashboardBundle\Extension;
  
  class NotificationTwigExtension extends \Twig_Extension
  {
      public function getFriendRequests($user)
      {
          $users = $this-&gt;getDoctrine()
              -&gt;getRepository('TennisconnectUserBundle:User')
              -&gt;getFriendRequests();
          return count($users);
      }
  
      public function getName()
      {
          return 'notification';
      }
  
      public function getFunctions()
      {
          return array(
              'getFriendRequests' =&gt; new \Twig_Function_Method($this, 'getFriendRequests'));
      }
  }
  </code></pre>