2017-08-10 17:18:22 +02:00
---
title: Content Sections
linktitle: Sections
2017-12-30 09:15:31 +01:00
description: "Hugo generates a **section tree ** that matches your content."
2017-08-10 17:18:22 +02:00
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [content management]
2017-09-21 19:03:00 +02:00
keywords: [lists,sections,content types,organization]
2017-08-10 17:18:22 +02:00
menu:
docs:
parent: "content-management"
weight: 50
weight: 50 #rem
draft: false
aliases: [/content/sections/]
toc: true
---
2018-03-16 09:44:54 +01:00
A **Section ** is a collection of pages that gets defined based on the
organization structure under the `content/` directory.
By default, all the **first-level ** directories under `content/` form their own
sections (**root sections**).
If a user needs to define a section `foo` at a deeper level, they need to create
a directory named `foo` with an `_index.md` file (see [Branch Bundles][branch bundles]
for more information).
{{% note %}}
A **section ** cannot be defined or overridden by a front matter parameter -- it
is strictly derived from the content organization structure.
{{% /note %}}
2017-12-30 09:15:31 +01:00
## Nested Sections
The sections can be nested as deeply as you need.
```bash
2018-03-16 09:44:54 +01:00
content
└── blog <-- Section, because first-level dir under content/
├── funny-cats
│ ├── mypost.md
│ └── kittens <-- Section, because contains _index.md
│ └── _index.md
└── tech <-- Section, because contains _index.md
└── _index.md
2017-12-30 09:15:31 +01:00
```
2018-03-16 09:44:54 +01:00
**The important part to understand is, that to make the section tree fully navigational, at least the lower-most section needs a content file. (e.g. `_index.md` ).**
2017-12-30 09:15:31 +01:00
2017-08-10 17:18:22 +02:00
{{% note %}}
2018-03-16 09:44:54 +01:00
When we talk about a **section ** in correlation with template selection, it is
currently always the * root section * only (`/blog/funny-cats/mypost/ => blog` ).
2017-12-30 09:15:31 +01:00
2018-02-27 09:36:36 +01:00
If you need a specific template for a sub-section, you need to adjust either the `type` or `layout` in front matter.
2017-08-10 17:18:22 +02:00
{{% /note %}}
2017-12-30 09:15:31 +01:00
## Example: Breadcrumb Navigation
2017-08-10 17:18:22 +02:00
2017-12-30 09:15:31 +01:00
With the available [section variables and methods ](#section-page-variables-and-methods ) you can build powerful navigation. One common example would be a partial to show Breadcrumb navigation:
2017-08-10 17:18:22 +02:00
2017-12-30 09:15:31 +01:00
{{< code file="layouts/partials/breadcrumb.html" download="breadcrumb.html" >}}
<ol class="nav navbar-nav">
{{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
</ol>
{{ define "breadcrumbnav" }}
{{ if .p1.Parent }}
{{ template "breadcrumbnav" (dict "p1" .p1.Parent "p2" .p2 ) }}
{{ else if not .p1.IsHome }}
{{ template "breadcrumbnav" (dict "p1" .p1.Site.Home "p2" .p2 ) }}
{{ end }}
<li{{ if eq .p1 .p2 }} class="active"{{ end }}>
<a href="{{ .p1.Permalink }}">{{ .p1.Title }}</a>
</li>
{{ end }}
{{< /code >}}
2017-08-10 17:18:22 +02:00
2017-12-30 09:15:31 +01:00
## Section Page Variables and Methods
2017-08-10 17:18:22 +02:00
2017-12-30 09:15:31 +01:00
Also see [Page Variables ](/variables/page/ ).
2017-08-10 17:18:22 +02:00
2018-05-04 09:44:21 +02:00
{{< readfile file="/content/en/readfiles/sectionvars.md" markdown="true" >}}
2017-12-30 09:15:31 +01:00
## Content Section Lists
2018-03-16 09:44:54 +01:00
Hugo will automatically create pages for each * root section * that list all of the content in that section. See the documentation on [section templates][] for details on customizing the way these pages are rendered.
2017-08-10 17:18:22 +02:00
## Content *Section* vs Content *Type*
2018-03-16 09:44:54 +01:00
By default, everything created within a section will use the [content `type` ][content type] that matches the * root section * name. For example, Hugo will assume that `posts/post-1.md` has a `posts` content `type` . If you are using an [archetype][] for your `posts` section, Hugo will generate front matter according to what it finds in `archetypes/posts.md` .
2017-08-10 17:18:22 +02:00
[archetype]: /content-management/archetypes/
[content type]: /content-management/types/
[directory structure]: /getting-started/directory-structure/
[section templates]: /templates/section-templates/
2018-03-16 09:44:54 +01:00
[branch bundles]: /content-management/page-bundles/#branch -bundles