1

Could anyone tell me how I can hide a field after user login? For example, at the top of my front page I have:

login | register

However, upon successful login, I would to hide this field.

The above 'login | register' field is just a 'div' block with 'href'.
One good example is the hiding of the default Drupal login block after login in.

I am using Drupal 7.

  • what version of drupal are you running? – Alex Petrov Mar 8 '12 at 18:17
  • alex, I am using drupal 7. – chlong Mar 8 '12 at 18:41
  • what part of drupal is creating 'login | register' eg a block, a variable, a what? – Jimajamma Mar 8 '12 at 18:46
  • jima, i created that myself – chlong Mar 8 '12 at 18:46
  • do you mean that you just put it to template file? Or do you created a block via Structure -> Blocks -> Add Block? – Alex Petrov Mar 8 '12 at 18:49
3

If you're outputting this directly in a template file it would be as simple as:

<?php if (user_is_anonymous()) : ?>

<a href="...">login</a> | <a href="...">register</a>

<?php endif; ?>

If you're using a block then you most likely won't want to put PHP code directly into it as that would involve using the evil eval() function. Instead you could add a new menu and use the block that's automatically created for that menu to output the links.

Since the menu system respects permissions, and the logged in users don't have access to the register or login page, the links simply won't show when a user is logged in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.