微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过 ACF 将图像馈送到 Twig / Timber WordPress

如何解决通过 ACF 将图像馈送到 Twig / Timber WordPress

在我的树枝模板中,我有以下内容

{% 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,

'title' 工作正常,任何其他类型的字段也是如此。由于某种原因,我无法让图像通过。我尝试了很多变体,例如:

{% 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" }

有人知道这是怎么回事吗?气死我了!

谢谢

解决方法

根据 timber / acf cheatsheet 您可能应该使用以下内容:

{% include '@hc/components/home-hero.twig' with {
        'image': Image(post.meta('header_image)),'title' : data.title_field
    }
%}

否则,如果您可以添加 home-hero.twig 的代码,以查看如何使用/查询图像变量,请参阅 similiar issue

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。