Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wondered if it is possible to use one specific template for just one structure.

My structure build up

So let me make this clear. I have a structure called "Onze Diensten" (Our Services) and inside are child structures that are the actual services that the website offers. These child structures use a template that I assigned to them through structure so that works perfectly. But what I want now is that the actual "Onze Diensten" gets it's own individual template which would show all the services on one page.

How do I do that? Thank you for taking the time reading my question.

What I hoped would be the solution is using routes. By adding a route that when you visit onze-diensten/ it would load up the template onze-diensten/onze-diensten/ (Which is the path to the template I want to use).

But it seems to completely ignore the route at all.

share|improve this question
up vote 4 down vote accepted

I can't answer it clearly, but I did a workaround for something similar.

I've loaded the same template for my structure but gave my structure 2 entry-types(overviewPage, detailPage).

Both entry types loaded the same template but got handled differently. So my template for the structure looked something like this:

{% if entry.type == 'overviewPage' %}
  {% include 'snippets/content_overviewPage.html' %}
{% elseif entry.type == 'detailPage' %}
  {% include 'snippets/content_detailPage.html' %}
{% endif %}

I hope to see on this thread how other people handle this.

share|improve this answer
    
Thanks for your input! This explanation I can understand I also saw another thread on the same issue I believe and apparently someone gave a very good solution. But I don't understand what he did probably because I am still new at Craft. But maybe it can help you so here is [the link.] (craftcms.stackexchange.com/questions/96/…) – Jeffrey Stevens Mar 2 at 8:46
    
But how do you give different handles to the same structure? My structure handle is onzeDiensten and all the child structures get the same handle. Which means that I can use {% if entry.type == 'onzeDiensten' %} but I can't make use of the elseif beneath it because all the structures have the handle of onzeDiensten. – Jeffrey Stevens Mar 2 at 9:13
    
Make sure to define a second entry.type in your structure. And add this new entry.type you your entries. You can than handle those entries depending on their entry.type. – Marco Schuler Mar 2 at 9:23
1  
Marco, you are a genius. It works. I tried it failed a couple of times but eventually it worked out great! So thank you so much now I can finally move on with my project. – Jeffrey Stevens Mar 2 at 11:07

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.

share|improve this answer

I just noticed something.

"Onze Diensten" is your structure. In this structure you made an entry "Onze Diensten" on the first structure level.

If this "Onze Diensten" entry only is an overview of all it's children entries and doesn't contain any extra content you could just remove the "Onze Diensten" entry and make all the children entries on the first structure level.

For the overview page you would load the index.html with some code like this:

{% for entry in craft.entries.section('onzeDiensten') %}
  <a href={{entry.url}}>{{entry.title}}</a>
{% endfor %}
share|improve this answer
1  
I need "Onze Diensten" To be an entry on it's own for the navigation plugin that I use. Otherwise I can't make a submenu with children in it. – Jeffrey Stevens Mar 2 at 10:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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