在twig模板中使用对象键作为包含文件

时间:2018-06-14 07:22:38

标签: php twig

早上好,

我正在尝试构建一个组件,其中数据以cson形式从cms到达。我需要能够使用数组中的对象作为要包含在树枝模板中的文件。像这样......

{%cards [{component: '@-card', cardOptions: {''}}, {component: '@-card_small', cardOptions: {''}}] %}

{% for card in cards %} {% include card.component with card.cardOptions only %} {% endfor %}

我遇到的问题似乎并没有解析' @'从json我得到错误" file.indexOf不是函数"。该项目设置为使用' @'作为前缀所以我无法改变它。我试图以各种方式连接,但没有任何作用。没有' @'符号就像我预期的那样解析。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

感谢您的替换建议DarkBee,我使用

修复了它
{% for card in cards %}
  {% set card = '@' ~ card.component %}
  {% include card with {card.cardOptions, card:card} only %}
{% endfor %}
相关问题