<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>

CC BY-SA 3.0
2017-12-09T03:11:13.403Z
There's also the slightly less verbose `{parent.uri}{{ object.getDescendants().total() != 0 ? '/' : '#' }}{slug}`
Paul
CC BY-SA 3.0
2017-12-09T03:04:49.113Z
2017-12-09T03:04:49.113Z
Paul
<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>

CC BY-SA 3.0
2017-12-08T17:43:46.087Z
What error is causing the tasks to get stuck?  It'll be logged in `craft/storage/runtime/logs`.
Brad Bell
CC BY-SA 3.0
2017-12-09T02:29:57.133Z
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.`
Paul
CC BY-SA 3.0
2017-12-09T02:35:46.380Z
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...
Paul
<url><structure><conditional>
Conditional anchor in structure url
# 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}`  

---

