$user not available

I have built a site with user authentication, following this tutorial from the cookbook


Login of registered users works.

Now, I want to show the username of the logged in user in the menu bar, using code like this in my templates:

<?php echo ($user->username()) ?>

Always get an error: Undefined variable: User

Kind of perplexed, should definitely work.

Any hint?

No, this won’t work if you don’t define your $user variable first:

if($user = $site->user()) {
  echo $user->username();

textnixe, you´re my life-saver!

Thank yo so much!