I want the logged in user to see his name and email address in the text of a paragraph on a given page, how to I extract that information from the currently logged in users account, and show it in the body of the page?

3 Answers 3


You can create a block with the PHP code format (don't forget to activate the PHP filter module) and put inside:

  //Retrieve the global variable for the connected user
  global $user; 
  echo 'Hello ' . $user->name;
  echo 'Your email is :' . $user->mail;

Then you set up this block to show only for authenticated users and you place it in a region.

See Drupal global variables documentation.

  • Thank you, this is exactly what I needed, and it works well.
    – Q Beat
    Commented Nov 2, 2011 at 23:38

You can also look into Token Filter - you add this as a processor on the text format and can then use tokens right within your content without having to enable the PHP module. Much more elegant. It may or may not work for your user tokens according to the project page, but definitely worth a shot.

  • I installed the token filter but had difficulty seeing any difference in my pages, types, etc. I must not be understanding exactly what Token filter does. I couldn't find documentation (although I probably don't know where to look). It didn't help me with this problem.
    – Q Beat
    Commented Nov 2, 2011 at 23:40
  • Yeah, if you are not used to using Tokens then the way you did it might be the best way to start for now. I recommend looking into them in the future though because allowing PHP code to be stored in the database and executed can always be a security risk, and it's harder to maintain. Commented Nov 3, 2011 at 1:37
  • Yes, I agree that I need to learn more about this, you have peaked my interest in Tokens and how to use them. What is the link to Token Filter documentation? Thanks in advance.
    – Q Beat
    Commented Nov 3, 2011 at 21:08
  • It's a bit sparse, unfortunately, but you can check out drupalcode.org/project/token_filter.git/blob/refs/heads/… Commented Nov 3, 2011 at 21:47

A simple way would be to create a view for those fields with a contextual filter "userid from logged in user". Use the block display and show it anywhere on your site.

Please specify if you have more specific layout requirements. As with anything in Drupal there many different ways of getting to the same results ;-)

  • I didn't want to use a different block, that's why I said that it was to replace given text within a given page.
    – Q Beat
    Commented Nov 2, 2011 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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