1

I need to create a features structure section for a website that will have parent features and child features.

Q1: How do I get different URL Format for parent & child pages?

  • I need the parent features here: website.com/features/parent-feature
  • And the Child features here website.com/parent-feature/child-feature

Q2: How do I display the Parent & Child in different templates? I want the parent features to look more dominant than the child features.

2

To get different URL Format for parent & child pages, you need to go to the CP structure settings and edit the Entry URI Format. This is how your URI should look like:

{% if level == 1 %}features/{slug}{% else %}{parent.slug}/{slug}{% endif %}

For your templating question, if you want a different template for parents and children, you need an if statement in your template file for that structure. So in your CP structure settings, you will have one template file: features/feature_entry.twig and inside that file you will have:

{% if entry.children|length %} 

   <!-- If it has a child, it's a parent page -->
   {% include 'features/_parent.twig' %}

{% else %}<!-- it's a child page -->

   {% include 'features/_child.twig' %}

{% endif %}

Just like that... You now have 2 different templates in 2 different .twig files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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