Answers.Body: <p>You have the full power of Twig in your template to render the entries Uri so you can conditionally render what you want. This could be your template in your section settings </p>
  
  <pre class="lang-twig prettyprint-override"><code>{% if object.parent.field == true %}{{ object.parent.uri }}{% else %}{{object.parent.slug}}{% endif %}
  </code></pre>
  
  <p>There are no real limitations since you can do what you are used to in Twig in your frontend </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T22:25:35.363Z
Answers.Text: Thanks for that. I feel like I'm close but not quite there. 
  `{% if object.parent.excludeFromUri %}{{ object.parent.slug }}{% else %}{{object.parent.uri}}{% endif %}/{slug}` - which doesn't quite do what I'm after as in the first condition, (where the exclude is true) I need to get the objects parent parents uri.
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T22:28:05.130Z
Answers.Text: Then add another `parent` to your output but check if there is a parent. You might want to do the following: create your well formatted code in your entries Twig template and set `{% set object = entry %}` and when you have the correct format you copy it in your cp.
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T22:48:23.720Z
Answers.Text: Ok, Got it working, not sure it's the best to be doing it as it only allows up to 4 levels, so it might be worth rewriting to enable it to handle any level, but I'm pretty sure 4 levels is more than enough for my needs. `{{ object.parent.parent.parent.excludeFromUri == 0 ? object.parent.parent.parent.slug~'/'  }}{{ object.parent.parent.excludeFromUri == 0 ? object.parent.parent.slug~'/'  }}{{ object.parent.excludeFromUri == 0 ? object.parent.slug~'/'  }}{{ object.slug }}` - bit of beast!
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T22:50:44.830Z
Answers.Text: You might want to think about coding a little bit more defensive cause I guess most of your entries can't be resaved because of the exceptions that are thrown
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T22:53:24.023Z
Answers.Text: Yea, just wanted to test it's possible then optimise.
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T22:57:22.307Z
Answers.Text: To clean up your code: you could loop your entries ancestors via reverse filter https://twig.symfony.com/doc/2.x/filters/reverse.html and do what you did above
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T23:12:44.153Z
Answers.Text: `{% if object.level > 1 %}
      {% for parent in object.getAncestors()  %}{{ parent.excludeFromUri != 1 ? parent.slug~'/' }}{% endfor %}
  {% endif %}{{ object.slug }}` - seems to do the job
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T23:17:45.367Z
Answers.Text: Seems good well done glad you got sorted
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T23:19:28.607Z
Answers.Text: Cheers, thanks for the nudge in the right direction. Was hitting a bit of a blank!
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T21:47:22.660Z
Answers.LastActivityDate: 2019-03-06T21:47:22.660Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have a structure where the Entry URI Format is <code>{parent.uri}/{slug}</code> - what I'm looking to do is conditionally not include entry slugs within the uri based on a show/hide setting in the entry.</p>
  
  <p>For example, I might have structure where an entry, <code>sub-page2</code> has a uri like so <code>page/sub-page/sub-page2</code> but if there is a setting on sub-page to exclude it, it's uri should be <code>page/sub-page2</code></p>
  
  <p>This would mean that the conditional to show it should only be considered if it's being called as a parent. <code>sub-page</code> should still be accessible from <code>page/sub-page</code> - trying to find a way to achieve this?</p>
  
Tags: <structure>
Title: Custom URI to exclude entries in structure
ThreadText: # Custom URI to exclude entries in structure
  
  (Asked by: username_0 on 2019-03-06)
  
  I have a structure where the Entry URI Format is `{parent.uri}/{slug}` - what I'm looking to do is conditionally not include entry slugs within the uri based on a show/hide setting in the entry.
  
  For example, I might have structure where an entry, `sub-page2` has a uri like so `page/sub-page/sub-page2` but if there is a setting on sub-page to exclude it, it's uri should be `page/sub-page2`
  
  This would mean that the conditional to show it should only be considered if it's being called as a parent. `sub-page` should still be accessible from `page/sub-page` - trying to find a way to achieve this?
  
  **Tags:** structure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-06. Score: 2 | Accepted answer
  
  You have the full power of Twig in your template to render the entries Uri so you can conditionally render what you want. This could be your template in your section settings
  
  ```twig
  {% if object.parent.field == true %}{{ object.parent.uri }}{% else %}{{object.parent.slug}}{% endif %}
  
  ```
  
  There are no real limitations since you can do what you are used to in Twig in your frontend
  
  > **Comments:**
  > **username_0**: Thanks for that. I feel like I'm close but not quite there.  `{% if object.parent.excludeFromUri %}{{ object.parent.slug }}{% else %}{{object.parent.uri}}{% endif %}/{slug}` - which doesn't quite do what I'm after as in the first condition, (where the exclude is true) I need to get the objects parent parents uri.  
  > **username_1**: Then add another `parent` to your output but check if there is a parent. You might want to do the following: create your well formatted code in your entries Twig template and set `{% set object = entry %}` and when you have the correct format you copy it in your cp.  
  > **username_0**: Ok, Got it working, not sure it's the best to be doing it as it only allows up to 4 levels, so it might be worth rewriting to enable it to handle any level, but I'm pretty sure 4 levels is more than enough for my needs. `{{ object.parent.parent.parent.excludeFromUri == 0 ? object.parent.parent.parent.slug~'/'  }}{{ object.parent.parent.excludeFromUri == 0 ? object.parent.parent.slug~'/'  }}{{ object.parent.excludeFromUri == 0 ? object.parent.slug~'/'  }}{{ object.slug }}` - bit of beast!  
  > **username_1**: You might want to think about coding a little bit more defensive cause I guess most of your entries can't be resaved because of the exceptions that are thrown  
  > **username_0**: Yea, just wanted to test it's possible then optimise.  
  > **username_1**: To clean up your code: you could loop your entries ancestors via reverse filter https://twig.symfony.com/doc/2.x/filters/reverse.html and do what you did above  
  > **username_0**: `{% if object.level > 1 %}     {% for parent in object.getAncestors()  %}{{ parent.excludeFromUri != 1 ? parent.slug~'/' }}{% endfor %} {% endif %}{{ object.slug }}` - seems to do the job  
  > **username_1**: Seems good well done glad you got sorted  
  > **username_0**: Cheers, thanks for the nudge in the right direction. Was hitting a bit of a blank!  
  
  ---
  
  