I would like to expose certain areas of pages only to admins, just like Drupal does out of the box, but incorporate that in my template.

Eg

<?php if ($user == 'admin') { ?>
Important Stuff
<?php } ?>

What are the variables I have to look for?

Thanks

Comments

DriesK’s picture

If you want to display something to certain roles, you could use

  global $user;
  $roles = $user->roles;
  if (in_array('rolename', $roles)) {
    print 'Important Stuff';
  }

If you mean user1:

  global $user;
  if ($user->uid == 1) {
    print 'Important Stuff';
  }
rszrama’s picture

If there's a specific permission you're wanting to check against, you can also use the following:

  global $user;
  if (user_access('permission')) {
    print 'Important Stuff';
  }

hook_menu() uses that to restrict access based on role permissions.

NicolasH’s picture

Many thanks, guys. Exactly what I was looking for...

Could someone point me to a resource that lists the variables that I can access on a page (like the $user array above)?

Cheers

rszrama’s picture

Hmm.. I'm not sure if there is one. hehe Maybe someone else knows of one, but I've just learned by developing for Drupal. Learning as you go...