title: Accessing the logged-in user in a template
body: <p>I'm using FOSuserbundle to get started with User registration <a href="https://github.com/FriendsOfSymfony/FOSUserBundle">https://github.com/FriendsOfSymfony/FOSUserBundle</a></p>
  
  <p>I've got it registering / logging in and out. What I want to do now is grab the logged in users data and present it on every page of my site. Like "Hi username" in the header type of thing.</p>
  
  <p>It seems like embedding a controller in my <strong>app/Resources/views/base.html.twig</strong> is the best way to do this <a href="http://symfony.com/doc/current/book/templating.html#embedding-controllers">http://symfony.com/doc/current/book/templating.html#embedding-controllers</a></p>
  
  <p>So I wrote my controller to access the user profile data. What I can't figure out is how to access FOS methods in my embedded controller. So from my <strong>Acme/UserBundle/Controller/UserController.php</strong> I want to do this:</p>
  
  <pre><code>public function showAction()
  {
      $user = $this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
      if (!is_object($user) || !$user instanceof UserInterface) {
          throw new AccessDeniedException(
                 'This user does not have access to this section.');
      }
  
      return $this-&gt;container-&gt;get('templating')
        -&gt;renderResponse('FOSUserBundle:Profile:show.html.'.$this-&gt;container
        -&gt;getParameter('fos_user.template.engine'), array('user' =&gt; $user));
  }
  </code></pre>
  
  <p>which I grabbed from:
  vendor/bundles/FOS/UserBundle/Controller/ProfileController.php</p>