【问题标题】:Cannot output image using render()无法使用 render() 输出图像
【发布时间】:2014-01-21 13:53:52
【问题描述】:

我正在尝试输出这张图片:

但是,没有任何东西被打印出来。我的代码是

print render($media_item->field_media_photo['und'][0]

为什么它不起作用?

【问题讨论】:

    标签: php drupal drupal-7 drupal-theming


    【解决方案1】:

    请改用image_style_url

    $image_uri = $media_item->field_media_photo['und'][0]['uri'];
    $image_stylePath = image_style_url("large", $image_uri);
    print theme("image", array(
        'path' => $image_stylePath
    ));
    

    【讨论】:

    【解决方案2】:

    它不会那样工作。 最好的方法是使用主题功能。

    $image = theme('image', $vars);
    $path = $media_item->field_media_photo['und'][0]['uri'];
    
    $vars =  array(
      'path' => $path , 
      'alt' => 'alt',
      'attributes' => array('class' => 'example'),
      );
    

    这里只有路径是强制性的。 您可以在 .tpl 文件中打印变量 $image,然后图像就会出现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-03
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-27
      相关资源
      最近更新 更多