如何检查 app.request.attributes.get('_route')==blog/slug 变量
How to check app.request.attributes.get('_route')==blog/slug variables
例如,如果我的 url 是
http://localhost/project/blog
我们可以通过
检查当前的 url 路线
{% if app.request.attributes.get('_route') == 'blog' %}
</p>this is default page</p>
{%endif%}
BUt 以下 url:
http://localhost/project/blog/2
这不起作用
{% if app.request.attributes.get('_route') == 'blog/2' %}
</p>this is blog page 2</p>
{%endif%}
尝试app.request.requestUri:应该return"project/blog/2"
{% if 'blog/2' in app.request.uri %}
</p>this is blog page 2</p>
{% endif %}
例如,如果我的 url 是
http://localhost/project/blog
我们可以通过
{% if app.request.attributes.get('_route') == 'blog' %}
</p>this is default page</p>
{%endif%}
BUt 以下 url:
http://localhost/project/blog/2
这不起作用
{% if app.request.attributes.get('_route') == 'blog/2' %}
</p>this is blog page 2</p>
{%endif%}
尝试app.request.requestUri:应该return"project/blog/2"
{% if 'blog/2' in app.request.uri %}
</p>this is blog page 2</p>
{% endif %}