2.3 KiB
title, linktitle, description, date, publishdate, lastmod, categories, tags, weight, draft, aliases, toc, needsreview
| title | linktitle | description | date | publishdate | lastmod | categories | tags | weight | draft | aliases | toc | needsreview | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Section Page Templates | Section Page Templates | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
|
40 | false | true | true |
Section page templates are lists and therefore have all the variables and methods available to list pages.
{{% warning "Section Pages Pull Content from _index.md" %}}
To effectively leverage section page templates, you should first understand the Hugo content organization, and specifically the purpose of _index.md.
{{% /warning %}}
Section Template Lookup Order
The lookup order for section pages is as follows:
- /layouts/section/
.html - /layouts/_default/section.html
- /layouts/_default/list.html
- /themes//layouts/section/
SECTION.html - /themes/
THEME/layouts/_default/section.html - /themes/
THEME/layouts/_default/list.html
Note that a sections list page can also have a content file with frontmatter, see Source Organization.
.Site.GetPage
Every Page in Hugo has a .Kind attribute. Kind can easily be combined with where in your templates to create kind-specific lists of content, but there are times where you may want to fetch the index page of a single section by the section's path.
.GetPage looks up an index page (i.e _index.md) of a given Kind and path. This method is only supported in section page templates but may support [single page templates][singlepages] in the future.
.Site.GetPage takes two arguments: kind and kind value.
The valid values for 'kind' are as follows:
homesectiontaxonomytaxonomyTerm
.Site.GetPage Example
The .Site.GetPage example assumes the following project directory structure:
{{% code file="grab-blog-section-index-page-title.html" %}}
{{ with .Site.GetPage "section" "blog" }}{{ .Title }}{{ end }}
{{% /code %}}
.Site.GetPage will return nil if no _index.md page is found. If content/blog/_index.md does not exist, the template will output a blank section where {{.Title}} should have been in the preceding example.