【发布时间】:2017-06-13 05:32:58
【问题描述】:
在 Symfony 3.2(使用 twig)中,我试图从数组中动态生成菜单项。
数组:
{% set links = {
dashboard: { path: 'dashboard', title: 'Home' },
page1: { path: 'page1', title: 'Page1' },
page2: { path: 'page2', title: 'Page1' },
}
%}
菜单项循环:
{% for link in links %}
<li>
<a {% if app.request.attributes.get('_route') == link.path %}
class="active"
{% endif %}
href="{{ path('{{link.path}}') }}">{{ link.title }}
</a>
</li>
{% endfor %}
我收到错误An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "{{link.path}}" as such route does not exist.")。
使用路径({{ link.path }})我收到错误A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{" in
【问题讨论】:
标签: loops syntax twig template-engine