<p>As mentioned in the comments: <code>{parent.uri}/{slug}</code> 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 <code>parent-slug/child-slug</code>. Every subsequent level appends their own slug as a new part to the URI.</p>

CC BY-SA 4.0
2021-10-23T17:59:28.737Z
Thanks! I knew there should be an easier way, I just couldn't find any examples.
Augustine Calvino
CC BY-SA 4.0
2021-10-23T07:39:58.670Z
2021-10-23T07:39:58.670Z
MoritzLost
<p>In my page structure entry type I put in a custom URI Format:</p>
<p><code>{{ object.getAncestors().all() | map(page =&gt; page.slug) | push(slug) | join('/') }}</code></p>
<p>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.</p>

CC BY-SA 4.0
2021-10-23T01:36:10.843Z
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. 
August Miller
CC BY-SA 4.0
2021-10-23T01:20:10.647Z
2021-10-23T01:20:10.647Z
Augustine Calvino
<p>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 <code>page_title</code> has a corresponding url, but its child page with a slug of <code>I-am-a-child-page</code> would have a url of <code>page_tile/I-am-a-child-page</code>. This formate should continue for arbitrary levels of nested pages.</p>
<p>How would I accomplish this?</p>

<url><structure><routes>
Make page urls correspond to their structure
# Make page urls correspond to their structure

(Asked by: username_0 on 2021-10-23)

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?

**Tags:** url, structure, routes


---

## 2 answers

### Answer by username_1 on 2021-10-23. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: Thanks! I knew there should be an easier way, I just couldn't find any examples.  

---

### Answer by username_0 on 2021-10-23. Score: 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.

> **Comments:**
> **username_2**: 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.   

---

