mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-14 20:17:17 +00:00
Add Section definition
Fixes https://github.com/gohugoio/hugoDocs/issues/409
This commit is contained in:
1 parent
4e7e1815b7
commit
19e99c957b
1 file changed
+27
-15
@@ -17,36 +17,49 @@ aliases: [/content/sections/]
|
|||||||
toc: true
|
toc: true
|
||||||
---
|
---
|
||||||
|
|
||||||
|
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 %}}
|
||||||
|
|
||||||
## Nested Sections
|
## Nested Sections
|
||||||
|
|
||||||
The sections can be nested as deeply as you need.
|
The sections can be nested as deeply as you need.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
blog
|
content
|
||||||
├── funny-cats
|
└── blog <-- Section, because first-level dir under content/
|
||||||
│ └── kittens
|
├── funny-cats
|
||||||
│ └── _index.md
|
│ ├── mypost.md
|
||||||
└── tech
|
│ └── kittens <-- Section, because contains _index.md
|
||||||
└── _index.md
|
│ └── _index.md
|
||||||
|
└── tech <-- Section, because contains _index.md
|
||||||
|
└── _index.md
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
**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`).**
|
**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`).**
|
||||||
|
|
||||||
|
|
||||||
{{% note %}}
|
{{% note %}}
|
||||||
When we talk about a **section** in correlation with template selection, it is currently always the root section only (`/blog/funny/mypost/ => blog`).
|
When we talk about a **section** in correlation with template selection, it is
|
||||||
|
currently always the *root section* only (`/blog/funny-cats/mypost/ => blog`).
|
||||||
|
|
||||||
If you need a specific template for a sub-section, you need to adjust either the `type` or `layout` in front matter.
|
If you need a specific template for a sub-section, you need to adjust either the `type` or `layout` in front matter.
|
||||||
{{% /note %}}
|
{{% /note %}}
|
||||||
|
|
||||||
|
|
||||||
## Example: Breadcrumb Navigation
|
## Example: Breadcrumb Navigation
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
|
|
||||||
{{< code file="layouts/partials/breadcrumb.html" download="breadcrumb.html" >}}
|
{{< code file="layouts/partials/breadcrumb.html" download="breadcrumb.html" >}}
|
||||||
<ol class="nav navbar-nav">
|
<ol class="nav navbar-nav">
|
||||||
{{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
|
{{ template "breadcrumbnav" (dict "p1" . "p2" .) }}
|
||||||
@@ -71,15 +84,14 @@ Also see [Page Variables](/variables/page/).
|
|||||||
|
|
||||||
## Content Section Lists
|
## Content Section Lists
|
||||||
|
|
||||||
Hugo will automatically create pages for each section root 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.
|
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.
|
||||||
|
|
||||||
## Content *Section* vs Content *Type*
|
## Content *Section* vs Content *Type*
|
||||||
|
|
||||||
By default, everything created within a section will use the [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`.
|
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`.
|
||||||
|
|
||||||
[archetype]: /content-management/archetypes/
|
[archetype]: /content-management/archetypes/
|
||||||
[content type]: /content-management/types/
|
[content type]: /content-management/types/
|
||||||
[directory structure]: /getting-started/directory-structure/
|
[directory structure]: /getting-started/directory-structure/
|
||||||
[section templates]: /templates/section-templates/
|
[section templates]: /templates/section-templates/
|
||||||
|
[branch bundles]: /content-management/page-bundles/#branch-bundles
|
||||||
|
|
||||||
Reference in new issue
Block a user