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?

  • 写回答

2条回答 默认 最新

  • dt4320279 2017-02-15 19:28
    关注

    If you're using {% set .. %}... {% endset %}, Twig is treating the variable as a string

    You should switch your code to this and then it works

    {% set navbar_logo = [ sprinkle~"/components/content/navbar/navbar-logo.html.twig", "/components/content/navbar/navbar-logo.html.twig"] %}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?