<p>You have twig syntax (<code>{{...}}</code>) inside twig syntax (<code>{%...%}</code>), which is never right. Does this work?</p>

<pre><code>{% if entry.hasDescendants() %}
  {% redirect entry.getChildren().first().url %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-02-13T02:10:07.150Z
@StephenCallender I don't think [getChildren()](http://buildwithcraft.com/docs/templating/entrymodel#getChildren) has been deprecated. It is an alias for `getDescendants(1)`
Marion Newlevant
CC BY-SA 3.0
2015-02-13T03:03:34.813Z
It is. See here: http://ssdd.d.pr/1hu9D
Stephen Callender
CC BY-SA 3.0
2015-02-13T03:05:16.710Z
I hadn't seen that it was alias for `getDescendants(1)`. I'll try that on my site.
Stephen Callender
CC BY-SA 3.0
2015-02-12T22:42:56.753Z
getChildren() has been deprecated. relatedTo() is suggested.
Stephen Callender
CC BY-SA 3.0
2014-08-20T17:18:48.227Z
2014-08-20T17:18:48.227Z
Marion Newlevant
<p>How can i redirect to the first child if an entry has children?</p>

<p>Something like this:</p>

<pre><code>{% if entry.hasDescendants() %}
    {% redirect "{{ entry.getChildren().first().url }}" %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-08-20T17:11:57.283Z
Why do you want to redirect, Johannes? What holds you back from linking to the right entry straight away?
carlcs
CC BY-SA 3.0
2014-08-20T17:33:33.907Z
See this Q/A for what I mean: ["Setting up redirects via Craft routes?"](http://craftcms.stackexchange.com/q/1488/125)
carlcs
<redirect>
How to redirect if entry has children?
# How to redirect if entry has children?

(Asked by: username_0 on 2014-08-20)

How can i redirect to the first child if an entry has children?
Something like this:
{% if entry.hasDescendants() %}
    {% redirect "{{ entry.getChildren().first().url }}" %}
{% endif %}

**Tags:** redirect
> **Comments:**
> **username_1**: Why do you want to redirect, Johannes? What holds you back from linking to the right entry straight away?  
> **username_1**: See this Q/A for what I mean: ["Setting up redirects via Craft routes?"](http://craftcms.stackexchange.com/q/1488/125)  

---

## 1 answers

### Answer by username_2 on 2014-08-20. Score: 7 | Accepted answer

You have twig syntax ({{...}}) inside twig syntax ({%...%}), which is never right. Does this work?
{% if entry.hasDescendants() %}
  {% redirect entry.getChildren().first().url %}
{% endif %}

> **Comments:**
> **username_3**: getChildren() has been deprecated. relatedTo() is suggested.  
> **username_2**: @StephenCallender I don't think [getChildren()](http://buildwithcraft.com/docs/templating/entrymodel#getChildren) has been deprecated. It is an alias for `getDescendants(1)`  
> **username_3**: It is. See here: http://ssdd.d.pr/1hu9D  
> **username_3**: I hadn't seen that it was alias for `getDescendants(1)`. I'll try that on my site.  

---

