簡體   English   中英

使用對象密鑰作為樹枝模板中的包含文件

[英]Using object key as the include file in twig template

早上好,

我試圖建立一個組件,其中數據從cms以json形式到達。 我需要能夠使用數組中的對象作為要包含在樹枝模板中的文件。 像這樣

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

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

我遇到的問題似乎無法從json解析“ @”,並且出現錯誤“ file.indexOf不是函數”。 該項目設置為使用“ @”作為前綴,因此我無法更改它。 IV嘗試以各種方式進行連接,但是沒有任何效果。 沒有'@'符號,它將按我的預期進行解析。

感謝您的任何幫助。

感謝您的替代建議DarkBee,我通過使用進行了修復

{% for card in cards %}
  {% set card = '@' ~ card.component %}
  {% include card with {card.cardOptions, card:card} only %}
{% endfor %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM