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.

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.

3 Answers 3



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.


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.

  • Thanks, I already have this setup. What I need is for a template to be loaded depending on whether the entry has children.
    – Martin
    Commented Jun 30, 2017 at 13:52
  • Your answer got me on the right road thanks
    – Martin
    Commented Jun 30, 2017 at 14:14
  • Cool. Could you post your solution or mark one of these as correct? Commented Jul 3, 2017 at 7:48

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.