2

I have a template which I want to use for different sections.

In my template I have this code:

{% set pages = craft.entries.section('catering').level(1) %}
<ul>
  {% for page in pages %}
    <li>{{ page.getLink() }}</li>
  {% endfor %}
</ul>

But I want to select the current section by Craft self. So I can use the same template for multiple sections.

2
2

To expand on my comment you could do this:

In templates/_pages/index.twig you would do:

{% include '_pages/_types/_' ~ entry.type %}

Then create a folder in /templates/_pages/ called _types in it use, an example _standard.twig in which "standard" coincides to your Entry Type slug.

I hope that helps. I couldn't find the original SE post but I know that this method has been mentioned and preferred by many Crafters!

1

What i want do is:

I will get all level 1 childs from the current Section to build a Subnav with it. Like:

{% set pages = craft.entries.section(getCurrentSection).level(1) %}

What i need to know is the current section handle. Thank you ;)

1
  • You really should update your question, not answering it in this way. – Mark Busnelli Jr Sep 2 '16 at 15:16

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.