如何将动态值传递到树枝/工艺cms中的另一个组件?

时间:2018-11-14 22:54:48

标签: twig octobercms craftcms

我需要标题来显示(当前日期-1) 当我硬编码一个值,例如“ 17”

这是组件(在索引中)显示的地方

MyRecord.connection.execute(
  "UPDATE my_records, units 
   SET unit_id = units.id 
   WHERE units.item_1 = legacy_column_1 AND units.item_2 = legacy_column_2"
)

此文件在哪---> 这就是我添加日期

的方式
   {% include 'home/key-facts' with {
        content: {
            keyFactsHeading: entry.keyFactsHeading,
            keyFacts: entry.keyFacts,
            keyFactsSmall: entry.keyFactsSmall,

        }

我正在将content.title传递到这里--->

{% 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> 我收到500错误。

title: {{ "now"|date('Y') - 1}}

这是为什么?您能否也解释一下为什么我的尝试不起作用? 我尝试倾倒 {% include '_components/bg-type' with { content: { title: 17 }, } only %} ,可以看到想要的年份

1 个答案:

答案 0 :(得分:1)

{{ ... }}表示法用于输出数据。在这种情况下,您只想将数据传递给包含。请注意,您已经在twig语句{% include .... %}

正确的语法是

{% include '_components/bg-type' with {
    content: {
        title:  "now"|date('Y') - 1,
   },
} only %}