2.8 KiB
title, linktitle, description, date, publishdate, lastmod, categories, tags, weight, draft, aliases, toc
| title | linktitle | description | date | publishdate | lastmod | categories | tags | weight | draft | aliases | toc | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Homepage Template | Homepage Template | The homepage of a website is often formatted differently than the other pages. For this reason, Hugo makes it easy for you to define your new site's homepage as a unique template. | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
|
30 | false |
|
false |
The homepage of a website is often formatted differently than the other pages. In Hugo you can define your own homepage template.
Homepage is a Page and therefore has all the page variables and site variables available for use.
{{% note "The Only Required Template" %}} The homepage template is the only required template for building a site and therefore useful when bootstrapping a new site and template. It is also the only required template if you are developing a single-page website. {{% /note %}}
Homepage Template Lookup Order
The lookup order for the homepage template is as follows:
/layouts/index.html/layouts/\_default/list.html/layouts/\_default/single.html/themes/<THEME>/layouts/index.html/themes/<THEME>/layouts/_default/list.html/themes/<THEME>/layouts/_default/single.html
.Data.Pages on the Homepage
In addition to the standard page variables, the homepage template has access to all site content via .Data.Pages.
.Data.Pages usually refers to the list of pages available within a given section or taxonomy. However, since index.html is the homepage of your Hugo project (i.e., in essence, the top of the master section), Data.Pages for layouts/index.html is interchangeable with .Site.Pages when written on the homepage template.
Note that a homepage can also have a content file with front matter. This content file lives at content/_index.md. See Content Organization for more information.
Example Homepage Template
The following is an example of a homepage template.
It makes use of partial templates and uses a similar approach as a Hugo list template.
{{% code file="layouts/index.html" download="index.html" %}}
{{ define "main" }}
{{ partial "content-header.html" . }}
<main aria-role="main">
<div>
<!-- Note that .Data.Pages is the equivalent of .Site.Pages on the homepage template. -->
{{ range first 10 .Data.Pages }}
{{ .Render "summary"}}
{{ end }}
</div>
</main>
{{ partial "content-footer.html" . }}
{{ end }}
{{% /code %}}