如何从当前URL获取相对URL

发布于 2025-01-12 23:25:58 字数 520 浏览 1 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星 2025-01-19 23:25:59

解决方案:{{ app.request.attributes.get('sw-original-request-uri') }}

Solution: {{ app.request.attributes.get('sw-original-request-uri') }}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文