0

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?

1 Answer 1

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

1
  • 1
    Hey Alexander, many thanks, this works! For the record: {% set termsAgreement = sulu_content_load('123-123-123-123', {'url': 'url' }) %} {% set termsAgreementUrl = sulu_content_path(privPolicy.content.url) %}
    – Mario A
    Commented Nov 21 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.