<p>There is not really a very simple way to do this. One thing to keep in mind is that <code>channels</code> and <code>structures</code> do not have an 'index' page defined by default. Essentially there are no uri's for channels and structures as a whole, only for the entries within them. You need to create index pages yourself, using:</p>

<ul>
<li><code>Singles</code> (one for each of your index pages), or</li>
<li>a <code>Structure</code> (using different <code>EntryTypes</code> for the different levels and/or page types), or</li>
<li>Template files (placed directly in your templates folder)</li>
</ul>

<p>The other problem is that you may have channels that do not represent pages at all, but are just collections of data to be used elsewhere; likewise, sections do not really have a way to define order. Overall not really a good mechanism to generate nav.</p>

<p>There are, however, other ways to do this.</p>

<p>One solution is to use a dedicated <code>Structure</code> specifically for navigation (called 'primaryNav' for example) with a related entries field that links to other entries and a custom url field to link to other pages as needed. You can then loop through that structure to generate your nav.</p>

<p>Another option is to define all of your top level pages (what might normally be considered singles) within a <code>structure</code> using <code>EntryTypes</code> to differentiate the various page types and define the field requirements (i.e. a structure called 'pages' for example). You can then loop through this structure to generate your nav, using the <code>EntryType</code> to determine which template code to display.</p>

<p>Either of these techniques can be used with other channels and or structures as needed to generate lower level pages where there are many of the same type (i.e. news, blog, articles, projects, etc.).</p>

<p>There are a lot of good examples of this on the exchange site. Also have a look at <a href="http://buildwithcraft.com/docs/templating/nav" rel="nofollow">craft's <code>nav</code> tag in the documentation</a>.</p>

CC BY-SA 3.0
2015-01-26T20:04:02.013Z
Thank you Douglas for your respond. Yes, you're right, there are several ways to build navigation. The best fit for my need is category group. Here is the link to arecipe, I found useful - http://craftcookbook.net/recipes/330
Dominik Krulak
CC BY-SA 4.0
2022-02-02T14:45:04.263Z
Thank you too! This might be an old post, but it opened my mind as to what `EntryTypes` really are useful for!
Alexander Rutz
CC BY-SA 3.0
2015-01-26T00:14:14.973Z
2015-01-26T01:54:40.867Z
2015-01-26T01:54:40.867Z
Douglas McDonald
<p>I've went through several examples related to my issue, but I quite couldn't find What I'm looking for.</p>

<p>Well, there <a href="https://craftcms.stackexchange.com/questions/64/how-to-write-simple-navigation">was one</a>, but with pre-defined array. 
What I'm looking for is to only output all my sections, with link and title +  at the matched section's URL, display all entries belonging under relevant section.</p>

<p>I've found here one snippet of code, which logic sounds about right to me, but it's like there's missing something.</p>

<pre><code>{% set sections = [] %}
{% for section in craft.sections.getAllSections() %}
{% if section.type == 'channel' %}
{% set sections = sections|merge([section]) %}
{% endif %}
{% endfor %}
</code></pre>

<p>Any help, or direction would be appreciated and I believe, it would help those, Who are like me at the beginning of this journey.</p>

<p>Thank you</p>

<navigation><sections>
How to build a navigation from sections
# How to build a navigation from sections

(Asked by: username_0 on 2015-01-25)

I've went through several examples related to my issue, but I quite couldn't find What I'm looking for.
Well, there was one, but with pre-defined array. 
What I'm looking for is to only output all my sections, with link and title +  at the matched section's URL, display all entries belonging under relevant section.
I've found here one snippet of code, which logic sounds about right to me, but it's like there's missing something.
{% set sections = [] %}
{% for section in craft.sections.getAllSections() %}
{% if section.type == 'channel' %}
{% set sections = sections|merge([section]) %}
{% endif %}
{% endfor %}

Any help, or direction would be appreciated and I believe, it would help those, Who are like me at the beginning of this journey.
Thank you

**Tags:** navigation, sections

---

## 1 answers

### Answer by username_1 on 2015-01-26. Score: 2 | Accepted answer

There is not really a very simple way to do this. One thing to keep in mind is that `channels` and `structures` do not have an 'index' page defined by default. Essentially there are no uri's for channels and structures as a whole, only for the entries within them. You need to create index pages yourself, using:

* `Singles` (one for each of your index pages), or
* a `Structure` (using different `EntryTypes` for the different levels and/or page types), or
* Template files (placed directly in your templates folder)

The other problem is that you may have channels that do not represent pages at all, but are just collections of data to be used elsewhere; likewise, sections do not really have a way to define order. Overall not really a good mechanism to generate nav.

There are, however, other ways to do this.

One solution is to use a dedicated `Structure` specifically for navigation (called 'primaryNav' for example) with a related entries field that links to other entries and a custom url field to link to other pages as needed. You can then loop through that structure to generate your nav.

Another option is to define all of your top level pages (what might normally be considered singles) within a `structure` using `EntryTypes` to differentiate the various page types and define the field requirements (i.e. a structure called 'pages' for example). You can then loop through this structure to generate your nav, using the `EntryType` to determine which template code to display.

Either of these techniques can be used with other channels and or structures as needed to generate lower level pages where there are many of the same type (i.e. news, blog, articles, projects, etc.).

There are a lot of good examples of this on the exchange site. Also have a look at [craft's `nav` tag in the documentation](http://buildwithcraft.com/docs/templating/nav).

> **Comments:**
> **username_0**: Thank you Douglas for your respond. Yes, you're right, there are several ways to build navigation. The best fit for my need is category group. Here is the link to arecipe, I found useful - http://craftcookbook.net/recipes/330  
> **username_2**: Thank you too! This might be an old post, but it opened my mind as to what `EntryTypes` really are useful for!  

---

