Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

What is the way to use tokens in PHP code?
I need to show the user profile picture URL, but the following code doesn't work.

<?php
  echo "[current-user:picture:url]";
?>

How do I display tokens in a block? I am using Drupal 7.

share|improve this question
 
drupal.org/project/token_filter use this module –  Mohammed Shameem Feb 1 at 12:42

2 Answers

You could try token_replace

token_replace($text, array $data = array(), array $options = array())

Parameters

$text: A string potentially containing replaceable tokens.

$data: (optional) An array of keyed objects. For simple replacement scenarios 'node', 'user', and others are common keys, with an accompanying node or user object being the value. Some token types, like 'site', do not require any explicit information from $data and can be replaced even if it is empty.

$options: (optional) A keyed array of settings and flags to control the token replacement process. Supported options are:

share|improve this answer

I dont recommend using PHP in a block for many reasons.

I would recommend you to use proper implementation of hook_block_view and hook_block_info to do you custom PHP codes in there.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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