Drupal 7令牌替换

han*_*sen 4 php token drupal-7

在变量中存储令牌替换的正确方法是什么?或者我应该打扰并直接打电话给他们?

像:

$author_uid = [node:author:uid];
$name = [node:title];
$picture = [node:field-image-upload:file];
$link = [node:url];
Run Code Online (Sandbox Code Playgroud)

给我一个错误:

PHP Parse error:  syntax error, unexpected ':'
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?

还有关于这一行:

$picture = [node:field-image-upload:file];
Run Code Online (Sandbox Code Playgroud)

我真正想要得到的是该图像文件的url链接.如何使用令牌执行此操作?

nmc*_*nmc 8

如果要将标记存储在变量中,则应编写 $author_uid = "[node:author:uid]";

请注意,令牌只是一个字符串.
文档中token.inc所述,令牌系统是......

API函数用于使用有意义的值替换文本中的占位符.

如果您想要URL链接到图像文件,您可以这样做:

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

请注意,您需要已将$node对象传递到令牌替换功能.