10

Plugging tokens into a block's title only shows the input text instead of what the token's supposed to output.

Is there a way to enable/use tokens in block titles, or maybe an alternative method of getting the results I want?

I've tried using Token Filter module, but it doesn't change the functionality.

I am trying to insert the [user:profile-realname] token into a block title (specifically the User Menu block title). The token is in my list of tokens available to use via HELP in the backend.

  • 1
    drupal version? where are you trying to set the title, inside a module or from the block admin page? what tokens are you trying to access? – Jimajamma Dec 21 '11 at 16:05
  • added version to title – Mechaflash Dec 21 '11 at 17:57
  • Created an edit – Mechaflash Dec 22 '11 at 20:13
  • a detail blog: goo.gl/77zEds – Suresh Kamrushi Jul 14 '15 at 11:38
7

AFAIK, this cannot be achieved using the block title field, however using the Token Filter module, you can just drop the token in the body area of the block and wrap it in an H2 tag and it will appear as if it was the block title. (Just set the block title to <none>)

| improve this answer | |
  • 1
    Does this also apply to the Node Title field? I want to add tokens to the Node title of the basic page content type, trying the same mechanism as Mechaflash. Will I also have to use Token Filter, or can I put Tokens directly into the Node title field (using the web interface, no php coding)? – David Csonka Feb 15 '12 at 16:16
  • no, it doesn't. If you wish to put it in the title field, you will need to follow Lance's answer to the question. – user842 Feb 15 '12 at 19:36
5

Try the token_replace() function in the block preprocessor. Example:

$node = menu_get_object();  // Get the current node
if ($node) {
  $vars['elements']['#block']->subject = token_replace($vars['elements']['#block']->subject, array('node' => $node));
}

Maybe you have to load the user too to have the user tokens available.

| improve this answer | |
  • I'm probably not going to try this as nicoz answer is the easiest way to do this. I would rather not mess with tpl files if I don't have to. – Mechaflash Jan 24 '12 at 16:26
2

Once Support token replacement for block titles is implemented, you'll be able to use the [current-user:profile-realname] token.

| improve this answer | |
  • 1
    So how do i reliable determine what tokens are going to validate? Or were you saying in that thread that there isn't a way to validate non-core tokens? – chrisjlee Sep 28 '12 at 14:57
1

Set Title to empty, and just add a Global Text Area in Views Header! Add here h tags or whatever html you want. Much easier and no coding required...

| improve this answer | |

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.