<p>Fixed!</p>

<p><a href="https://craftcms.com/support/entry-type-templates" rel="nofollow noreferrer">So bearing in mind i'm using this method to load templates according to entry type</a>, Clive Portman's answer got me thinking about hasDescendants.  In my _entry.html I now have something like this:</p>

<pre><code>{% if entry.hasDescendants() %}
  {% include "products/_types/secType_categoryGroupOverview.html" %}
{% else %}
  {% include "products/_types/secType_productSpecification.html" %}
{% endif %}
</code></pre>

<p>...and it seems to work as required :)</p>

<p>Obviously happy to hear of any more elegant solutions.</p>

CC BY-SA 3.0
2017-06-30T14:14:16.040Z
2017-07-03T08:53:03.167Z
2017-07-03T08:53:03.167Z
Martin
<p>It might be easier to have the products point to the same template, then create two sub-templates that you include depending on the entry type.</p>

<p>For example, I have a template called <code>landing/pages/_entry.html</code> that contains the following:</p>

<pre><code>{% include "landing-pages/_entryTypes/_" ~ entry.type %}
</code></pre>

<p>with several sub-templates named after the respective entry types.</p>

<p>Alternatively, you could probably use <code>hasDescendants</code> (<a href="https://craftcms.com/docs/templating/entrymodel#hasDescendants" rel="nofollow noreferrer">docs</a>) but in my experience it's more forgiving when go by entry type.</p>

CC BY-SA 3.0
2017-06-30T13:52:05.907Z
Thanks, I already have this setup.  What I need is for a template to be loaded depending on whether the entry has children.
Martin
CC BY-SA 3.0
2017-06-30T14:14:53.630Z
Your answer got me on the right road thanks
Martin
CC BY-SA 3.0
2017-07-03T07:48:49.953Z
Cool. Could you post your solution or mark one of these as correct?
Clive Portman
CC BY-SA 3.0
2017-06-30T11:52:15.923Z
2017-06-30T11:52:15.923Z
Clive Portman
<p>I agree with the other answers that your best solution is to just render a different template and don't do a redirect. But, if you do find a more applicable use later, you can do in-template redirects like this:</p>

<pre><code>{% if not entry.hasDescendants() %}
  {% redirect '/your/product/url' %}
{% endif %}
</code></pre>

<p>If you do this, it's recommended that you do it as high in the template as possible, so you hit the redirect before the server does more work than it has to.</p>

CC BY-SA 3.0
2017-06-30T14:42:33.617Z
2017-06-30T14:42:33.617Z
Megan Z.
<p>I have a Structure Section called 'products' which uses two EntryTypes, one for 'Product Type Overview' and one for 'Individual Products', where 'Individual Products' are the children of 'Product Type Overview'.  Some 'products' have children and some do not.</p>

<p>I have a menu which then lists the top level entries, so in most cases the user selects 'Product A' they see a list of items (variations) belonging to 'Product A', they then click on an item to see more information about that particular product variation. -  This I have done without a problem using <a href="https://craftcms.com/support/entry-type-templates" rel="nofollow noreferrer">this method</a>.</p>

<p>Here's my problem...  If the user selects a product that DOES NOT have variations (children) I need them to go straight to the child template and miss the parent 'Overview' template.</p>

<p>I hope that makes sense?</p>

<p>Any help very much appreciated.</p>

<templating><structure><redirect><entry-type>
Redirect to another EntryType template if no Children exist
# Redirect to another EntryType template if no Children exist

(Asked by: username_0 on 2017-06-30)

I have a Structure Section called 'products' which uses two EntryTypes, one for 'Product Type Overview' and one for 'Individual Products', where 'Individual Products' are the children of 'Product Type Overview'. Some 'products' have children and some do not.

I have a menu which then lists the top level entries, so in most cases the user selects 'Product A' they see a list of items (variations) belonging to 'Product A', they then click on an item to see more information about that particular product variation. - This I have done without a problem using [this method](https://craftcms.com/support/entry-type-templates).

Here's my problem... If the user selects a product that DOES NOT have variations (children) I need them to go straight to the child template and miss the parent 'Overview' template.

I hope that makes sense?

Any help very much appreciated.

**Tags:** templating, structure, redirect, entry-type

---

## 3 answers

### Answer by username_0 on 2017-06-30. Score: 3 | Accepted answer

Fixed!
So bearing in mind i'm using this method to load templates according to entry type, Clive Portman's answer got me thinking about hasDescendants.  In my _entry.html I now have something like this:
{% if entry.hasDescendants() %}
  {% include "products/_types/secType_categoryGroupOverview.html" %}
{% else %}
  {% include "products/_types/secType_productSpecification.html" %}
{% endif %}

...and it seems to work as required :)
Obviously happy to hear of any more elegant solutions.


---

### Answer by username_1 on 2017-06-30. Score: 2

It might be easier to have the products point to the same template, then create two sub-templates that you include depending on the entry type.
For example, I have a template called landing/pages/_entry.html that contains the following:
{% include "landing-pages/_entryTypes/_" ~ entry.type %}

with several sub-templates named after the respective entry types.
Alternatively, you could probably use hasDescendants (docs) but in my experience it's more forgiving when go by entry type.

> **Comments:**
> **username_0**: Thanks, I already have this setup.  What I need is for a template to be loaded depending on whether the entry has children.  
> **username_0**: Your answer got me on the right road thanks  
> **username_1**: Cool. Could you post your solution or mark one of these as correct?  

---

### Answer by username_2 on 2017-06-30. Score: 2

I agree with the other answers that your best solution is to just render a different template and don't do a redirect. But, if you do find a more applicable use later, you can do in-template redirects like this:
{% if not entry.hasDescendants() %}
  {% redirect '/your/product/url' %}
{% endif %}

If you do this, it's recommended that you do it as high in the template as possible, so you hit the redirect before the server does more work than it has to.


---

