Answers.Body: <p>There was a typo hidden in there, otherwise the logic works. To get children as anchors in a structure, the following should do the trick:</p>
  
  <p><code>{parent.uri}{% if object.getDescendants().total() != 0 %}/{% else %}#{% endif %}{slug}</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-09T03:11:13.403Z
Answers.Text: There's also the slightly less verbose `{parent.uri}{{ object.getDescendants().total() != 0 ? '/' : '#' }}{slug}`
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-09T03:04:49.113Z
Answers.LastActivityDate: 2017-12-09T03:04:49.113Z
Answers.UserDisplayName: Paul
Body: <p>I have a structure section, where the last child should be an anchor in the slug:</p>
  
  <p><code>parent/parent#child</code></p>
  
  <p>I'm trying to setup conditional url formats on nested entries as such:</p>
  
  <p><code>{parent.uri}{% if object.getDescendants().total() != 0 %)/{% else %}#{% endif %}{slug}</code></p>
  
  <p>I've also tried the simpler</p>
  
  <p><code>{parent.uri}{% if object.hasDescendants %)/{% else %}#{% endif %}{slug}</code></p>
  
  <p>but keep getting stuck tasks when re-saving entries. Can someone tell me what I'm doing wrong? Thanks in advance</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-08T17:43:46.087Z
Comments.Text: What error is causing the tasks to get stuck?  It'll be logged in `craft/storage/runtime/logs`.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-09T02:29:57.133Z
Comments.Text: there's a lot in the craft.log, something like this? `[error] [application] Encountered an error running task 18 (ResaveElements), step 2 of 39: An exception was thrown while trying to save the Entry with the ID “19”: Unexpected ")" in "{{object.parent.uri|raw}}{% if object.getDescendants().total() != 0 %)/{% else %}#{% endif %}{{object.slug|raw}}" at line 1.`
Comments.UserDisplayName: Paul
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-09T02:35:46.380Z
Comments.Text: Argh! I see my mistake right after I press submit. Fixed the typo and now all is good. Not sure how this has evaded me for so long yesterday...
Comments.UserDisplayName: Paul
Tags: <url><structure><conditional>
Title: Conditional anchor in structure url
ThreadText: # Conditional anchor in structure url
  
  (Asked by: username_0 on 2017-12-08)
  
  I have a structure section, where the last child should be an anchor in the slug:
  
  `parent/parent#child`
  
  I'm trying to setup conditional url formats on nested entries as such:
  
  `{parent.uri}{% if object.getDescendants().total() != 0 %)/{% else %}#{% endif %}{slug}`
  
  I've also tried the simpler
  
  `{parent.uri}{% if object.hasDescendants %)/{% else %}#{% endif %}{slug}`
  
  but keep getting stuck tasks when re-saving entries. Can someone tell me what I'm doing wrong? Thanks in advance
  
  **Tags:** url, structure, conditional
  
  > **Comments:**
  > **username_1**: What error is causing the tasks to get stuck?  It'll be logged in `craft/storage/runtime/logs`.  
  > **username_0**: there's a lot in the craft.log, something like this? `[error] [application] Encountered an error running task 18 (ResaveElements), step 2 of 39: An exception was thrown while trying to save the Entry with the ID “19”: Unexpected ")" in "{{object.parent.uri|raw}}{% if object.getDescendants().total() != 0 %)/{% else %}#{% endif %}{{object.slug|raw}}" at line 1.`  
  > **username_0**: Argh! I see my mistake right after I press submit. Fixed the typo and now all is good. Not sure how this has evaded me for so long yesterday...  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-12-09. Score: 2
  
  There was a typo hidden in there, otherwise the logic works. To get children as anchors in a structure, the following should do the trick:
  
  `{parent.uri}{% if object.getDescendants().total() != 0 %}/{% else %}#{% endif %}{slug}`
  
  > **Comments:**
  > **username_0**: There's also the slightly less verbose `{parent.uri}{{ object.getDescendants().total() != 0 ? '/' : '#' }}{slug}`  
  
  ---
  
  