Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-13T02:10:07.150Z
Answers.Text: @StephenCallender I don't think [getChildren()](http://buildwithcraft.com/docs/templating/entrymodel#getChildren) has been deprecated. It is an alias for `getDescendants(1)`
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-13T03:03:34.813Z
Answers.Text: It is. See here: http://ssdd.d.pr/1hu9D
Answers.UserDisplayName: Stephen Callender
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-13T03:05:16.710Z
Answers.Text: I hadn't seen that it was alias for `getDescendants(1)`. I'll try that on my site.
Answers.UserDisplayName: Stephen Callender
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-12T22:42:56.753Z
Answers.Text: getChildren() has been deprecated. relatedTo() is suggested.
Answers.UserDisplayName: Stephen Callender
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-20T17:18:48.227Z
Answers.LastActivityDate: 2014-08-20T17:18:48.227Z
Answers.UserDisplayName: Marion Newlevant
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-20T17:11:57.283Z
Comments.Text: Why do you want to redirect, Johannes? What holds you back from linking to the right entry straight away?
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-20T17:33:33.907Z
Comments.Text: See this Q/A for what I mean: ["Setting up redirects via Craft routes?"](http://craftcms.stackexchange.com/q/1488/125)
Comments.UserDisplayName: carlcs
Tags: <redirect>
Title: How to redirect if entry has children?
ThreadText: # 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, username_0? 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**: @username_3 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.  
  
  ---
  
  