首页 > 解决方案 > 在 Views php 字段中渲染图像

问题描述

我需要在 Views GUI 中使用 php 字段。我已经完成了所有设置,但我无法渲染我的图像。使用 $row->field_image 时,我得到一个包含 [0] => 152 的数组。那是什么?那是图像的实体吗?

我将如何在那里渲染我的图像?事实上,只是图像样式的 url 就可以了。这是 Drupal 8。

标签: drupaldrupal-8drupal-views

解决方案


由于这只是一些基本的验证,我最终使用了 twig,它工作得很好。在“自定义文本”字段中,它是这样的:

{% if field_image_item|trim is not empty %}
   <img src="{{ field_image_item }}" alt="{{ title }}">
{% elseif field_image_item_1|trim is not empty %}
   <img src="{{ field_image_item_1 }}" alt="{{ title }}">
{% endif %}

我想下次我会想办法在 php 中做到这一点:/


推荐阅读