Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 Token Replacements

What is the proper way to store token replacements in a variable? Or should i even bother and call them directly?

Things like:

$author_uid = [node:author:uid];
$name = [node:title];
$picture = [node:field-image-upload:file];
$link = [node:url];

Are giving me an error:

PHP Parse error:  syntax error, unexpected ':'

Am i doing something wrong?

Also in regards to this line:

$picture = [node:field-image-upload:file];

What I'm really trying to get is the url link to that image file. How can I do this with a token?

like image 723
hanleyhansen Avatar asked Feb 19 '23 16:02

hanleyhansen


1 Answers

If you want to store a token in a variable, you should write $author_uid = "[node:author:uid]";

Note that the token is just a string.
As noted in the documentation for token.inc, the token system is an...

API functions for replacing placeholders in text with meaningful values.

If you want the URL Link to the image file, you could do:

$picture = token_replace('[node:field-image-upload:file]', array('node' => $node));

Note that you would need to already have the $node object to pass into the token replacement function.

like image 93
nmc Avatar answered Feb 22 '23 06:02

nmc