Answers.Body: <p>I don't think the ternary operator does what you want it to do. According to <a href="https://twig.symfony.com/doc/3.x/templates.html#other-operators" rel="nofollow noreferrer">this page</a>, the first part of your URL format would return <code>1</code> (true) if the parent uri is not <code>__home__</code>, or an empty string if it is.</p>
  
  <p>You could try:</p>
  
  <p><code>{ parent.uri != '__home__' ? parent.uri }/{slug}</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-20T12:26:41.063Z
Answers.Text: Yes, of course. Thank you,
Answers.UserDisplayName: jishi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-19T20:53:34.517Z
Answers.LastActivityDate: 2020-02-19T20:53:34.517Z
Answers.UserDisplayName: Paul
Body: <p>I tried setting up a URL format that takes the hierarchy of a structure into account, but deals with the magic <code>__home__</code> slug transparently. </p>
  
  <p>So I did this:</p>
  
  <p><code>{parent.uri == '__home__' ? '' : parent.uri}/{slug}</code> </p>
  
  <p>Which works, but I wanted to tighten it up using the twig ternary <code>?:</code>, like this: </p>
  
  <p><code>{parent.uri != '__home__' ?: ''}/{slug}</code></p>
  
  <p>But that doesn't work at all, seems to choke on the <code>?:</code> part. Is that a bug, or just a short-coming of the URL format system (not being actual twig)?</p>
  
Tags: <craft3><entry-slug>
Title: Entry UrI Format and ternary operators
ThreadText: # Entry UrI Format and ternary operators
  
  (Asked by: username_0 on 2020-02-19)
  
  I tried setting up a URL format that takes the hierarchy of a structure into account, but deals with the magic `__home__` slug transparently.
  
  So I did this:
  
  `{parent.uri == '__home__' ? '' : parent.uri}/{slug}`
  
  Which works, but I wanted to tighten it up using the twig ternary `?:`, like this:
  
  `{parent.uri != '__home__' ?: ''}/{slug}`
  
  But that doesn't work at all, seems to choke on the `?:` part. Is that a bug, or just a short-coming of the URL format system (not being actual twig)?
  
  **Tags:** craft3, entry-slug
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-19. Score: 2 | Accepted answer
  
  I don't think the ternary operator does what you want it to do. According to [this page](https://twig.symfony.com/doc/3.x/templates.html#other-operators), the first part of your URL format would return `1` (true) if the parent uri is not `__home__`, or an empty string if it is.
  
  You could try:
  
  `{ parent.uri != '__home__' ? parent.uri }/{slug}`
  
  > **Comments:**
  > **username_0**: Yes, of course. Thank you,  
  
  ---
  
  