Twig - 获取规范标签的 URL [英] Twig - Get URL for canonical tag

查看:39
本文介绍了Twig - 获取规范标签的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的应用程序中创建一个动态 rel="canonical" 标记,该标记会拉入当前 URL,但希望确保删除所有查询参数.例如 http://www.example.com/test/?page=2 应该将规范作为 http://www.example.com/test/,因此 {{ app.request.uri }} 不起作用,因为这也会引入 ?page=2.

I'm looking to create a dynamic rel="canonical" tag in my application which pulls in the current URL but want to ensure any query parameters are removed. E.g http://www.example.com/test/?page=2 should have the canonical as http://www.example.com/test/, therefore {{ app.request.uri }} doesn't work as this pulls in ?page=2 as well.

有谁知道如何在没有查询参数的情况下拉入页面的绝对路径?

Does anyone know how to pull in the absolute path of a page without the query parameters?

推荐答案

这行得通,

{{ url(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }}

这篇关于Twig - 获取规范标签的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆