所以我有这个节点:
object(Drupal\node\Entity\Node)[1862]
protected 'values' =>
array (size=17)
'vid' =>
array (size=1)
'x-default' => string '7' (length=1)
'langcode' =>
array (size=1)
'x-default' =>
array (size=1)
0 =>
array (size=1)
'value' => string 'en' (length=2)
... (more fields)
'field_image' =>
array (size=1)
'x-default' =>
array (size=1)
0 =>
array (size=5)
'target_id' => string '1' (length=1)
'alt' => string '' (length=0)
'title' => string '' (length=0)
'width' => string '150' (length=3)
'height' => string '120' (length=3)
现在,field_image具有一个x-default数组和一些基本图像数据。如何显示图像,或在Twig模板中创建指向图像的链接?
Recoverable fatal error: Object of class Drupal\Core\Field\FieldItemList could not be converted to string
所以我尝试了这个: url(node.field_image.0.entity.uri.value)
但是然后它告诉了我:Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Route "public://image.png" does not exist.")
FieldItemList
s转换为字符串表示形式(我找不到)
url()
想要一条路线。怎么url_from_path(node.field_image.0.entity.uri.value)
样
url_from_path()
似乎产生这样的:http://mywebsite.local/public%3A//image.png
所以它似乎是URL编码和附加的精确值的url
url(node.field_image.0.entity.uri)
(相关问题)