如何在 Shopware 6 中通过 twig 将产品 URL 添加到电子邮件?
我想通过电子邮件发送产品链接。
我尝试在我的电子邮件树枝中使用 {{ seoUrl('frontend.detail.page', { 'productId': Product.id }) }}
生成 URL。但链接的格式似乎不正确。缺少域,而是显示域占位符。
结果如下所示: 124c71d524604ccbad6042edce3ac799/detail/47a05ce596394f95943f6e77b652dcab#
如何正确设置链接格式?
I would like to send links to products in an E-Mail.
I tried to generate URLs using {{ seoUrl('frontend.detail.page', { 'productId': product.id }) }}
in my E-Mail twig. But the links dont seem to be formatted correctly. The domain is missing and the domain placeholder is being displayed instead.
The result is looking like this: 124c71d524604ccbad6042edce3ac799/detail/47a05ce596394f95943f6e77b652dcab#
How can I correctly format my links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
rawUrl
函数应该可以。Using the
rawUrl
function should work.我知道,为时已晚,但希望它能帮助将来的人...
正如 @Alex 正确提到的那样,不会调用
\Shopware\Core\Content\Seo\SeoUrlPlaceholderHandler::replace
方法在你的场景中。它仅从StorefrontController::renderStorefront()
方法调用,因此要获得漂亮的 seo url,您需要使用StorefrontController
扩展控制器并返回$this-> ;renderStorefront(...)
:没有 StorefrontController 的替代解决方案
如果由于某种原因您无法使用
StorefrontController
,您可以只使用所需的功能StorefrontController::renderStorefront()
:I know, it is too late, but hope it will help someone in future...
As @Alex correctly mentioned, the
\Shopware\Core\Content\Seo\SeoUrlPlaceholderHandler::replace
method is not called in your scenario. It is called only from theStorefrontController::renderStorefront()
method, so to get nice seo urls you need extend your controller withStorefrontController
and return$this->renderStorefront(...)
:Alternative solution without StorefrontController
If for some reason you cannot use
StorefrontController
, you may just use the needed functionality fromStorefrontController::renderStorefront()
: