如何将动态值传递给twig/craft cms中的另一个组件?
我需要标题来显示(当前日期-1) 当我硬编码一个值时,例如“17” 这是组件显示的位置(在索引中) 这是哪个文件--> 我就是这样把日期包括进去的如何将动态值传递给twig/craft cms中的另一个组件?,twig,octobercms,craftcms,Twig,Octobercms,Craftcms,我需要标题来显示(当前日期-1) 当我硬编码一个值时,例如“17” 这是组件显示的位置(在索引中) 这是哪个文件--> 我就是这样把日期包括进去的 {% include '_components/bg-type' with { content: { title: {{ "now"|date('Y') - 1 }} }, } only %} 我正在将content.t
{% include '_components/bg-type' with {
content: {
title: {{ "now"|date('Y') - 1 }}
},
} only %}
我正在将content.title传递到此处-->
为什么会这样?你能解释一下为什么我所尝试的不起作用吗?
我尝试过转储
{{“now”{date('Y')-1}
,我可以看到我想要的年份使用{…}
符号输出数据。在这种情况下,您只希望向include传递数据。请注意,您已经在细枝
-语句中,{%include….%}
正确的语法应该是
{% include '_components/bg-type' with {
content: {
title: "now"|date('Y') - 1,
},
} only %}
<div class="bg-type">
<div class="bg-type__text bg-type--large">
{{ content.title }}
</div>
</div>
{% include '_components/bg-type' with {
content: {
title: 17
},
} only %}
{% include '_components/bg-type' with {
content: {
title: "now"|date('Y') - 1,
},
} only %}