4

I'm trying to use global variables in Entry URLs generated by Craft, but they seem to be empty. Not getting any errors as such, just null.

My Entry URL format looks like this:

{{siteDefaults.artworksList.first.uri|default}}/{slug}

Where artworkList is an entry with a URI/URL but I'm getting "/some-entry-slug"

Similarly, {{siteDefaults.artworksList.length}} returns 0 even though there is an entry there.

Has anyone tried to use globals before in entry URLs?

Thanks!

1 Answer 1

5

Your CraftCMS global can be accessed using the code

{{craft.globals.getSetByHandle('siteDefaults').artworksList.first.uri|default}}/{slug}

I believe the issue is that the Entry URL field requires you to use craft.globals to prevent issues with the routing custom variables.

1
  • 1
    The Craft 3 equivalent is craft.app.getGlobals().getSetByHandle('siteDefaults'). Commented Oct 13, 2018 at 12:08

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.