如何从当前URL获取相对URL
我是 Shopware 6 及其模板引擎 Twig 的新手,但我需要主题中当前 URL 的相对 URL。问题是数据库中几乎所有数据都是二进制的,所以如果我使用:
{{ app.request.pathInfo }}
或者 {{ app.request.requesturi }}
我总是得到这样的输出:
/detail/eccbc87e4b5ce2fe28308fd9f2a7baf3
但浏览器中的当前 URL 是一个搜索友好的 URL。
和: {{ seoUrl('frontend.detail.page', { ProductId: page.product.id }) }}
我以搜索友好的格式获得绝对 URL,但每次尝试替换主机和方案都会失败,并且出现错误。我只能替换 /、detail 或 eccbc87e4b5ce2fe28308fd9f2a7baf3,但不能替换主机,也不能替换方案。
有谁知道如何获取相对 URL?
I am new with Shopware 6 and its template engine Twig, but I need relative URL from current URL in theme. The problem is that almost all data in database are binary, so if I use:
{{ app.request.pathInfo }}
or{{ app.request.requesturi }}
I always get such output:
/detail/eccbc87e4b5ce2fe28308fd9f2a7baf3
but the current URL in browser is a search friendly URL.
With:{{ seoUrl('frontend.detail.page', { productId: page.product.id }) }}
I get the absolute URL in a search friendly format, but every try to replace host and scheme fails and I get an error. I can only replace /, detail or eccbc87e4b5ce2fe28308fd9f2a7baf3, but not host and not scheme.
Does anybody know what to do to get relative URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案:
{{ app.request.attributes.get('sw-original-request-uri') }}
Solution:
{{ app.request.attributes.get('sw-original-request-uri') }}