在 Symfony 2 中使用 Twig 路径函数创建带有锚点的链接
我正在尝试在 Twig 模板中创建一个带有“www.example.com/services#anchor1”这样的锚点的链接。到目前为止,我一直在使用 path 函数来创建链接 path('services')
。我尝试过 path('services#anchor1')
但显然它不起作用。
关于这个功能的信息好像不是很多或者只是找不到。知道我该怎么做吗?
谢谢!
I'm trying to create a link with an anchor like "www.example.com/services#anchor1" in my Twig template. So far I've been using the path function to create links path('services')
. I have tried with path('services#anchor1')
but obviously it doesn't work.
It doesn't seem to be a lot of information about this function or it's just that I can't find it. Any idea about how could I do it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
Home
Try
<a href="{{ path('_welcome') }}#home">Home</a>
从 Symfony 3.2 开始,您可以使用
_fragment
选项:查看 功能介绍。
As of Symfony 3.2 you can use the
_fragment
option:Check out the feature introduction on the Symfony blog.
我也有同样的问题。我刚刚在 a 标签中生成了链接,但随后需要在新页面中打开,即添加
target="_blank"
到生成的 url,所以我将 href 更改为此并且它起作用了!I had the same problem. I had just link being generated in the a tag but then needed to open in a new page aka add
target="_blank"
to the generated url so I changed the href to this and it worked!