【问题标题】:Can't get the author's picture printed onto a node in Drupal 7无法将作者的图片打印到 Drupal 7 中的节点上
【发布时间】:2012-08-18 02:35:21
【问题描述】:

阅读文档后,似乎正确的做法是这样的:

<?php print $user_picture; ?>

Wich 不起作用(它根本不打印任何东西)。

四处询问后,我得到了这个答案,遗憾的是这也不起作用:

<?php global $user;
$image = theme('user_picture', $user);
print $image;?>

该代码被建议为“最后一个资源”,但当我尝试使用它时,我收到以下错误消息:

致命错误:在第 1054 行的 /includes/theme.inc 中无法使用 stdClass 类型的对象作为数组

寻找那个特定的行:如果(isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {,并且在上下文中:

  if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
    $element = $variables;
    $variables = array();
    if (isset($info['variables'])) {
      foreach (array_keys($info['variables']) as $name) {
        if (isset($element["#$name"])) {
          $variables[$name] = $element["#$name"];
        }
      }
    }

pretty clear 应该可以工作,但它没有。

使用 contemplate 模块,我得到这个输出作为替代:

<?php print $node->picture ?>

这也行不通。

我已经尝试过使用 Devel 模块(使用节点的 /devel 选项卡):

我明白了:

picture (String, 4 characters ) 2876
$...->picture

这不起作用,因为输出只是“2876”,但却是那里唯一的“图片”。

那我该怎么办?我该如何追踪这个问题?

【问题讨论】:

  • -1 没有任何评论或解释?
  • +1,对我来说似乎是一个有效的问题。

标签: drupal variables drupal-7 image


【解决方案1】:

注意

theme('user_picture', $vars);

是一个 tpl.php 文件。 你可以为这个主题函数 dpm($vars) 预处理函数,看看你可以使用什么。

【讨论】:

    【解决方案2】:

    根据 Drupal 文档中的 node.tpl.php topic,$user_picture 是 node.tpl.php 文件中的有效变量(及其变体,如 node--book.tpl.php)

    这段代码是错误的:

    <?php global $user;
    $image = theme('user_picture', $user);
    print $image;?>
    

    它是关于显示当前用户的图片,它不适用于 Drupal 7 AFAIK。 如果 $user_picture 仍然不适合您,请尝试 node.tpl.php 中的 dsm($content) 或 dsm($node) 查找正确的变量。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 2012-02-11
    • 2017-09-03
    • 1970-01-01
    相关资源
    最近更新 更多