在变量中存储 token 替换的正确方法是什么?或者我应该直接调用他们吗?
比如:
$author_uid = [node:author:uid];
$name = [node:title];
$picture = [node:field-image-upload:file];
$link = [node:url];
给我一个错误:
PHP Parse error: syntax error, unexpected ':'
我做错了什么吗?
另外关于这一行:
$picture = [node:field-image-upload:file];
我真正想要获取的是指向该图像文件的 url 链接。我如何使用 token 执行此操作?
最佳答案
如果你想在变量中存储一个标记,你应该这样写$author_uid = "[node:author:uid]";
请注意 token 只是一个字符串。
如 the documentation for token.inc
中所述, token 系统是一个...
API functions for replacing placeholders in text with meaningful values.
如果你想要图像文件的 URL 链接,你可以这样做:
$picture = token_replace('[node:field-image-upload:file]', array('node' => $node));
请注意,您需要已经有 $node
对象才能传递到 token replacement function .
关于php - Drupal 7 token 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11764932/