6

Could somebody give me an example of how to use token_replace()?
I'm trying to write a custom PHP rule for the Rules module that will rewrite few fields of a new saved content, using the values from tokens.

13
$text = token_replace('token example - [node:title]', array('node' => node_load(123)));
  • thats really works for me :) – WaQaR Ali May 16 '17 at 13:24
3

As you are asking about how to replace tokens in a Rules action that is executing custom PHP code, you don't need to replace the tokens with token_replace().

If you enter something similar to the following code, the tokens will be replaced by the Rules module.

drupal_set_message(t('This is the node ID: %node-id', array('%node-id' => [node:nid]));

The list of the available tokens is reported in the custom PHP action page.

screenshot

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.