github.com/lyeb/hugo@v0.47.1/docs/content/en/templates/homepage.md (about)

     1  ---
     2  title: Homepage Template
     3  linktitle: Homepage Template
     4  description: 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.
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  categories: [templates]
     9  keywords: [homepage]
    10  menu:
    11    docs:
    12      parent: "templates"
    13      weight: 30
    14  weight: 30
    15  sections_weight: 30
    16  draft: false
    17  aliases: [/layout/homepage/,/templates/homepage-template/]
    18  toc: true
    19  ---
    20  
    21  Homepage is a `Page` and therefore has all the [page variables][pagevars] and [site variables][sitevars] available for use.
    22  
    23  {{% note "The Only Required Template" %}}
    24  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.
    25  {{% /note %}}
    26  
    27  {{< youtube ut1xtRZ1QOA >}}
    28  
    29  ## Homepage Template Lookup Order
    30  
    31  See [Template Lookup](/templates/lookup-order/).
    32  
    33  ## Add Content and Front Matter to the Homepage
    34  
    35  The homepage, similar to other [list pages in Hugo][lists], accepts content and front matter from an `_index.md` file. This file should live at the root of your `content` folder (i.e., `content/_index.md`). You can then add body copy and metadata to your homepage the way you would any other content file.
    36  
    37  See the homepage template below or [Content Organization][contentorg] for more information on the role of `_index.md` in adding content and front matter to list pages.
    38  
    39  ## `.Pages` on the Homepage
    40  
    41  In addition to the standard [page variables][pagevars], the homepage template has access to *all* site content via `.Pages`.
    42  
    43  ## Example Homepage Template
    44  
    45  The following is an example of a homepage template that uses [partial][partials], [base][] templates, and a content file at `content/_index.md` to populate the `{{.Title}}` and `{{.Content}}` [page variables][pagevars].
    46  
    47  {{< code file="layouts/index.html" download="index.html" >}}
    48  {{ define "main" }}
    49      <main aria-role="main">
    50        <header class="homepage-header">
    51          <h1>{{.Title}}</h1>
    52          {{ with .Params.subtitle }}
    53          <span class="subtitle">{{.}}</span>
    54          {{ end }}
    55        </header>
    56        <div class="homepage-content">
    57          <!-- Note that the content for index.html, as a sort of list page, will pull from content/_index.md -->
    58          {{.Content}}
    59        </div>
    60        <div>
    61          <!-- Note that .Pages is the same as .Site.RegularPages on the homepage template. -->
    62          {{ range first 10 .Pages }}
    63              {{ .Render "summary"}}
    64          {{ end }}
    65        </div>
    66      </main>
    67  {{ end }}
    68  {{< /code >}}
    69  
    70  [base]: /templates/base/
    71  [contentorg]: /content-management/organization/
    72  [lists]: /templates/lists/
    73  [lookup]: /templates/lookup-order/
    74  [pagevars]: /variables/page/
    75  [partials]: /templates/partials/
    76  [sitevars]: /variables/site/