【发布时间】:2021-06-17 10:54:52
【问题描述】:
在我的树枝模板中,我有以下内容:
{% include '@hc/components/home-hero.twig' with {
'image': '/assets/images/home-hero.png',
'title' : 'Title goes here',
要从 Wordpress 上的 ACF 字段中获取信息,我执行以下操作:
{% include '@hc/components/home-hero.twig' with {
'image': Image(data.hero_image),
'title' : data.title_field,
“标题”可以正常工作,任何其他类型的字段也是如此。出于某种原因,我无法让图像通过。我尝试了很多变体,例如:
{% set header_image %} {{ post.meta('header_image') }} {% endset %}
{% include '@hc/components/home-hero.twig' with {
'image': header_image,
在转储 header_image 时,我得到以下信息:
object(Twig\Markup)#2380 (2) {["content":protected]=>string(66) "url of image is in here" ["charset":protected]=>string(5) "UTF-8" }
有人知道发生了什么吗?快把我逼疯了!
谢谢
【问题讨论】:
-
data.hero_image返回什么?如果是url或者id,试试Image(data.hero_image).src