Skip to main content
added 311 characters in body
Source Link

Building off of Marco's first answer:

In your case, perhaps the easiest approach is to have a conditional in your Structure's entry template that checks the entry's level property, and includes different templates based on that - i.e. if the entry's level is 1, that means the entry is top level, and Craft should load an overview template. If not, the single service template should be served.

Something like this should do the trick – I'm assuming you have a template folder called "services", with three templates: index.twightml (which is the Structure's entry template), overview.twightml and service.twightml, and the following would go inside the entry template:

{% if entry.level == 1 %}
    {% include 'services/overview' %}
{% else %}
    {% include 'services/service' %}
{% endif %}

Note that with this setup, you can just put "services" (without the quotes) for your Structure Section's Entry Template field; then Craft will load the "services/index.html" template whenever an entry from this Structure is requested, and the above conditional will make sure the correct template is served.

Another approach entirely is to create a dropdown field (called structureTemplate or the like) for your Structure, which is hard coded to the following values:

service : Service template
overview : Service overview template

This would enable you to select the template on an entry basis. Here's how you could handle this in your entry template:

{% set template = entry.structureTemplate|default('service') %}
{% include 'services/'~template %}

I really think the first approach is better for your use case, though – considering that top level entries should always load one template and child level entries should always load another.

Building off of Marco's first answer:

In your case, perhaps the easiest approach is to have a conditional in your Structure's entry template that checks the entry's level property, and includes different templates based on that - i.e. if the entry's level is 1, that means the entry is top level, and Craft should load an overview template. If not, the single service template should be served.

Something like this should do the trick – I'm assuming you have a template folder called "services", with three templates: index.twig (which is the Structure's entry template), overview.twig and service.twig, and the following would go inside the entry template:

{% if entry.level == 1 %}
    {% include 'services/overview' %}
{% else %}
    {% include 'services/service' %}
{% endif %}

Another approach entirely is to create a dropdown field (called structureTemplate or the like) for your Structure, which is hard coded to the following values:

service : Service template
overview : Service overview template

This would enable you to select the template on an entry basis. Here's how you could handle this in your entry template:

{% set template = entry.structureTemplate|default('service') %}
{% include 'services/'~template %}

I really think the first approach is better for your use case, though – considering that top level entries should always load one template and child level entries should always load another.

Building off of Marco's first answer:

In your case, perhaps the easiest approach is to have a conditional in your Structure's entry template that checks the entry's level property, and includes different templates based on that - i.e. if the entry's level is 1, that means the entry is top level, and Craft should load an overview template. If not, the single service template should be served.

Something like this should do the trick – I'm assuming you have a template folder called "services", with three templates: index.html (which is the Structure's entry template), overview.html and service.html, and the following would go inside the entry template:

{% if entry.level == 1 %}
    {% include 'services/overview' %}
{% else %}
    {% include 'services/service' %}
{% endif %}

Note that with this setup, you can just put "services" (without the quotes) for your Structure Section's Entry Template field; then Craft will load the "services/index.html" template whenever an entry from this Structure is requested, and the above conditional will make sure the correct template is served.

Another approach entirely is to create a dropdown field (called structureTemplate or the like) for your Structure, which is hard coded to the following values:

service : Service template
overview : Service overview template

This would enable you to select the template on an entry basis. Here's how you could handle this in your entry template:

{% set template = entry.structureTemplate|default('service') %}
{% include 'services/'~template %}

I really think the first approach is better for your use case, though – considering that top level entries should always load one template and child level entries should always load another.

Source Link

Building off of Marco's first answer:

In your case, perhaps the easiest approach is to have a conditional in your Structure's entry template that checks the entry's level property, and includes different templates based on that - i.e. if the entry's level is 1, that means the entry is top level, and Craft should load an overview template. If not, the single service template should be served.

Something like this should do the trick – I'm assuming you have a template folder called "services", with three templates: index.twig (which is the Structure's entry template), overview.twig and service.twig, and the following would go inside the entry template:

{% if entry.level == 1 %}
    {% include 'services/overview' %}
{% else %}
    {% include 'services/service' %}
{% endif %}

Another approach entirely is to create a dropdown field (called structureTemplate or the like) for your Structure, which is hard coded to the following values:

service : Service template
overview : Service overview template

This would enable you to select the template on an entry basis. Here's how you could handle this in your entry template:

{% set template = entry.structureTemplate|default('service') %}
{% include 'services/'~template %}

I really think the first approach is better for your use case, though – considering that top level entries should always load one template and child level entries should always load another.