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.

Luke Pearce
  • 3,863
  • 1
  • 11
  • 25
The Frog
  • 119
  • 11
  • If you're using entry types to control your templates have a look at https://craftcms.com/support/entry-type-templates – Mark Busnelli Jr Aug 30 '16 at 15:48
  • Hi Alex, I'm afraid I don't understand what you're asking. You can set the template for a section in the control panel. Maybe read through this article to get a grasp of it: http://withchief.com/blog/craft-cms-the-very-basics-of-templating – Luke Pearce Aug 30 '16 at 15:51

2 Answers2

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!

Mark Busnelli Jr
  • 926
  • 7
  • 18
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 ;)

The Frog
  • 119
  • 11