I'd like to be able to use the username in the block title for a Nice Menu block. I thought it might be as simple as using some kind of variable like:

Welcome, <$user->username>.

as the block title (or something to that effect) but evidently not. What is the best way to accomplish this?

Just the username itself as the block title would be fine as well. Ideally, i'd like to be able to control what title is used for anonymous users as well but it's not needed for this project as this nice menu is only shown to authenticated users.

Any tips are appreciated.

Comments

mcjim’s picture

Reusing some of the code here: http://drupal.org/node/58602
you can come up with something like this to use in your theme's block.tpl.php file:

<?php global $user;
if($block->subject == 'your unique title') {
$block->subject = 'Wecome' . check_plain($user->name);
} ?>

Hope this sets you on the right track.

Veazer’s picture

Thanks, that's exactly what I was looking for. I wish Drupal had a list of variables that could be used to do this through admin, but this will accomplish exactly what I needed. Much appreciated!

akolahi’s picture

thank you for this. I found this very helpful!

sunketh’s picture

Can be used to create custom titles to blocks. Thanks! Edited the file block.tpl.php like this:
Original:

    <?php if ($block->subject): ?>
      <h2 class="block-title"><?php print $block->subject; ?></h2>
    <?php endif; ?>

New:

    <?php if ($block->subject): ?>
      <h2 class="block-title"><?php $block->subject; ?>
    <?php endif; 
    global $user;
    if($block->subject == 'Your Block title Here') {
        $block->subject = 'Hello ' . check_plain($user->name) . '!';
      }
    print $block->subject; ?></h2>