admin管理员组文章数量:1122826
If I want to create a link to a page in a Sulu twig template, I can use the <sulu-link />
tag, which is fine for most usecases. But sometimes I do not want an anchor tag rendered, but only the URL, for example to pass it to a javascript function or to use it in a form action.
In Sulu v2.5 this worked:
{% set termsAgreement = sulu_content_load('123-123-123-123') %}
{% set termsAgreementUrl = sulu_content_path(termsAgreement.urls[request.defaultLocale]) %}
Unfortunately this does not work in Sulu v2.6, as the urls
property is not returned anymore by sulu_content_load
. According to the sulu docs the urls
property is deprecated.
Of course, something like this would work
{% set termsAgreementUrl = sulu_content_path('/terms-agreement') %}
assuming the resourcelocator for the desired page is "terms-agreement". But when the resourelocator is changed in the admin interface, the url is broken.
So long story short: How can I get the URL to a Sulu page in twig by using its content id?
If I want to create a link to a page in a Sulu twig template, I can use the <sulu-link />
tag, which is fine for most usecases. But sometimes I do not want an anchor tag rendered, but only the URL, for example to pass it to a javascript function or to use it in a form action.
In Sulu v2.5 this worked:
{% set termsAgreement = sulu_content_load('123-123-123-123') %}
{% set termsAgreementUrl = sulu_content_path(termsAgreement.urls[request.defaultLocale]) %}
Unfortunately this does not work in Sulu v2.6, as the urls
property is not returned anymore by sulu_content_load
. According to the sulu docs the urls
property is deprecated.
Of course, something like this would work
{% set termsAgreementUrl = sulu_content_path('/terms-agreement') %}
assuming the resourcelocator for the desired page is "terms-agreement". But when the resourelocator is changed in the admin interface, the url is broken.
So long story short: How can I get the URL to a Sulu page in twig by using its content id?
Share Improve this question edited Nov 21, 2024 at 11:28 Mario A asked Nov 21, 2024 at 11:19 Mario AMario A 3,3401 gold badge19 silver badges23 bronze badges1 Answer
Reset to default 1The urls
is deprecated if you still want it you need to enable it. You should only use url
to get the current url.
Mention in the UPGRADE file: https://github.com/sulu/sulu/blob/2.6/UPGRADE.md#deprecated-urls-variable-in-return-value-of-sulu_content_load
本文标签: phpGet URL to a Sulu page by content idStack Overflow
版权声明:本文标题:php - Get URL to a Sulu page by content id - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311471a1934748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论