如何检查当前页面是否为此路径:
{{ path('someNamePath') }}
Run Code Online (Sandbox Code Playgroud)
我想为<a>元素设置一个css类,或者可以完全删除它,例如
{% if isCurrentPath('someNamePath') %}
<a href="{{ path('someNamePath') }}" class="YouAreHere">My Link</a>
{% else %}
<a href="{{ path('someNamePath') }}">My Link</a>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
Ond*_*ták 78
app.request.get('_route') 可能就是你在寻找的东西:
{% if app.request.get('_route') == 'current_route' %}
<a href="{{ path('current_route') }}" class="YouAreHere">My Link</a>
{% else %}
<a href="{{ path('some_other_route') }}">My Link</a>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
如果你想使用uri,你可以使用app.request.uri.