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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

The 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