doupu9251
2017-02-15 18:58
浏览 119
已采纳

如何从数组中包含twig文件?

Hi how do I pass a array to a twig include?

{% set navbar_logo %}["{{sprinkle|raw}}/components/content/navbar/navbar-logo.html.twig", "/components/content/navbar/navbar-logo.html.twig"]{% endset %}

{% include navbar_logo %}

this results in:

Unable to find template "["@admin/components/content/navbar/navbar-logo.html.twig", "/components/content/navbar/navbar-logo.html.twig"]"

this works fine:

{% include ["{{sprinkle|raw}}/components/content/navbar/navbar-logo.html.twig", "/components/content/navbar/navbar-logo.html.twig"] %}

But i need to get it from the variable.

This also works:

 {% set navbar_logo %}{{sprinkle|raw}}/components/content/navbar/navbar-logo.html.twig{% endset %}

{% include navbar_logo %}

But I need the backup incase the first one does not exist. How can I do this?

图片转代码服务由CSDN问答提供 功能建议

我如何将数组传递给树枝包括?

 <  code> {%set navbar_logo%} [“{{sprinkle | raw}} / components / content / navbar / navbar-logo.html.twig”,“/ component / content / navbar / navbar-logo.html.twig”]  {%endset%} 
 
 {%include navbar_logo%} 
   
 
 

这会导致:

  无法找到模板“[”@ admin / components / content / navbar / navbar-logo.html.twig“,”/ components / content / navbar / navbar-logo.html.twig“]”
  <  / pre> 
 
 

这很好用:

  {%include [“{{sprinkle | raw}} / components / content / navbar / navbar-logo  .html.twig“,”/ component / content / navbar / navbar-logo.html.twig“]%} 
   
 
 

但我需要从 变量。

这也有效:

  {%set navbar_logo%} {{sprinkle | raw}} / components / content / navbar  /navbar-logo.html.twig{% endset%} 
 
 {%include navbar_logo%} 
   
 
 

但是我需要第一个备份的备份 不存在。 怎么样? 我这样做了吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题