【问题标题】:twig {% image string %} with concated stringtwig {% image string %} with concat string
【发布时间】:2013-10-07 08:50:13
【问题描述】:

我有这样的代码

{% for i in 1..25 %}
  <li class="span4">
  {% set screen = '@TfptPortfolioBundle/Resources/public/images/bekic/screen' ~ i ~ '.jpg' %}
  <a href="#myModal" class="thumbnail" data-toggle="modal">{% image screen %}
  <img src="{{ asset_url }}" alt="Młody Lider Innowacji" />
  {% endimage %}</a>
  </li>
{% endfor %}

但是 symfony 在车道上抛出错误“Unexpected token “name” of value “screen””

<a href="#myModal" class="thumbnail" data-toggle="modal">{% image screen %}

如何连接字符串以将其用作资产 url?

【问题讨论】:

    标签: symfony twig


    【解决方案1】:

    所以它起作用了:

    {% for i in 1..25 %}
      <li class="span4">
        {% set screen = 'bundles/tfptportfolio/images/bekic/screen' ~ i ~ '.jpg' %}
        <a href="#myModal" class="thumbnail" data-toggle="modal">
           <img src="{{ asset(screen) }}" alt="Młody Lider Innowacji" />
        </a>
      </li>
    {% endfor %}
    

    显然您必须执行命令app/console assets:install --symlink 才能在网络目录上创建链接。

    编辑:

    以您所做的方式在标签资产中输入变量是不可能的。 为此,您必须在 config.yml 中声明变量。

    您可以在此处查看文档:documentation assetic

    目前唯一的方法就是我上面描述的。

    【讨论】:

    • 我在互联网上发现了 {% image %},它工作正常。它有一个优点 - 根本不需要安装资产。但是如果没有其他方法我需要安装那么:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    相关资源
    最近更新 更多