with
我正在将 Pattern Lab 与树枝模板一起使用,并且在包含的语句中直接使用对象时遇到问题。
这是我的teaser-content-blocks
有机体:
{% set content_blocks = [
{
teaser_photo: {
url: 'https://img.buzzfeed.com/buzzfeed-static/static/enhanced/terminal01/2011/3/29/17/enhanced-buzz-14894-1301433714-5.jpg',
alt: 'Man sleeping on a cake',
title: 'Man sleeping on a cake',
height: '200px',
width: '400px',
},
}
] %}
<div class="teaser-content-blocks">
{% for content_block in content_blocks %}
{% include '@molecules/teaser-content-block.twig' with content_block only %}
{% endfor %}
</div>
这是teaser-photo
原子:
<div class="teaser-photo">
<img
src="{{ url }}"
alt="{{ alt }}"
title="{{ title }}"
/>
</div>
这就是我试图用teaser-content-block
分子做的事情:
<div class="teaser-content-block">
<div class="left">
{% include '@atoms/teaser-photo.twig' with teaser_photo only %}
</div>
<div class="right">
{% include '@atoms/title.twig' with { title: 'Sleep on a cake', element: 'h3' } only %}
{% include '@atoms/teaser-body.twig' with { body: "When we say 'sweet dreams', this isn't quite what we mean! Check this mad lad not understanding the general concept of pillows! This utter banterboy has completely confused what he is meant to use as a confectionary-based celebration of one's birth and a soft item of bedding designed to cushion the head during sleep or light rest. Mental!" } only %}
</div>
</div>
但是,该with teaser_photo only
语句似乎导致 twig 中断并且无法编译,错误为Catchable fatal error: Argument 1 passed to Twig_Template::display() must be of the type array, null given
.
如果我将该包含语句更改为以下内容:
{% include '@atoms/teaser-photo.twig' with { url: teaser_photo.url, alt: teaser_photo.alt, title: teaser_photo.title } only %}
...它工作正常,但这对我来说太冗长了。我宁愿将对象按原样传递。它似乎只是不想以正确的方式拾取它,即使理论上它应该工作相同。
我不是树枝专家,所以我可能遗漏了一些非常明显的东西。
一如既往地感谢任何帮助!