In Craft 2.x you have the option of setting the top-level entries URL format for a structure section separately from nested entries i.e. top-level/{slug} and {parent.uri}/{slug}

But in Craft 3 the same URL format is applied for all entries within the structure section.

This means if you use top-level/{parent.uri}/{slug} it works fine for a top-level entry but then nested entries have the first segment duplicated, e.g. top-level/top-level/some-parent/the-slug. How does one achieve the same level of URL formatting for structure entries in Craft 3?


To pull off the same functionality in Craft 3, you could use something like this:

  • 3
    Awesome, thanks Brad. Might be worth somehow including this in the CP field instructions for a structure or elsewhere in the craft doco as I would assume most people would want this format for a structure section. :) Jan 26 '18 at 2:08
  • 7
    I ended up using the following: {% if level == 1 %}{section.handle}{% else %}{parent.uri}{% endif %}/{slug} Jan 28 '18 at 7:23
  • 5
    the accepted answer turned out faulty on my craft 3 version. I ended up using {parent.uri ?? 'top-level'}/{slug} and solved my issue of duplicated segments while allowing for a fixed segment. The solution of Rich could be rewritten as {parent.uri ?? section.handle}/{slug} for readability purposes
    – 3xil3
    Jan 29 '19 at 22:59
  • 3xil3 has the correct answer.
    – biko
    Apr 4 '19 at 4:14
  • After trying all answers here and at the related question here: craftcms.stackexchange.com/q/26483/4060 , the only answer that seems to allow for a static, non-duplicated segment in the url is here: craftcms.stackexchange.com/a/26484/4060
    – Tchick
    Sep 22 '19 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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