I want to display users' profile data from Hybridauth, so I used "Token Filter" to get the token codes (something like [hybridauth:firstName] ), then I put token_replace in 'user-profile.tpl.php':

print token_replace('[hybridauth:provider]', array('hybridauth', $hybridauth));

But Drupal give me an error message:

Notice: Undefined variable: hybridauth in include() (line 41 of /var/www/html/sites/all/themes/mytheme/templates/user-profile.tpl.php).

Anyone have any idea about this?


@Jia-Jun Xu In drupal8 To replace global token type


Here,$data contains the data from where you have to replace the token.

And if you want to replace a custom token.Then first define it in .module file and then replace IT.

use Drupal\Core\Render\BubbleableMetadata;

enter image description here

to replace [node:expirydate] from the data

print_r(\Drupal::service('token')->replace($data,array('node' => ' ')));

Here $data contains data from where token has to be replaced and 'node' is token type.For more information visit on below link How to programmatically create a custom token in a module https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Utility%21Token.php/function/Token%3A%3Areplace/8.2.x Hope it will be useful to you.

| 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.