1

I set up a page entry type under Structures, and because this is for generic pages, I want it to be arbitrarily nestable. From the structure page, this is easy to set up; however, I want the urls for those entries to correspond to the structure hierarchy - i.e. a root level page with a slug of page_title has a corresponding url, but its child page with a slug of I-am-a-child-page would have a url of page_tile/I-am-a-child-page. This formate should continue for arbitrary levels of nested pages.

How would I accomplish this?

2 Answers 2

2

As mentioned in the comments: {parent.uri}/{slug} is the simplest way to do this. This is basically like a recursive function: Top level pages habe no parent, so their URL is just the slug. Second level pages have a parent with a simple slug as their URI, they get something like parent-slug/child-slug. Every subsequent level appends their own slug as a new part to the URI.

1
  • Thanks! I knew there should be an easier way, I just couldn't find any examples. Commented Oct 23, 2021 at 17:59
1

In my page structure entry type I put in a custom URI Format:

{{ object.getAncestors().all() | map(page => page.slug) | push(slug) | join('/') }}

If you want help understanding the meaning of that, just ask! If anyone else has a simpler / more readable way to do that, I'm all ears.

1
  • I think you're basically replicating what {parent.uri}/{slug} would achieve! These "object templates" fail silently, so if the Entry is at the root, it'll just output nothing. 👍 Commented Oct 23, 2021 at 1:36

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.