HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
gohugoio Star
  • About Hugo
    • Overview
    • What is Hugo
    • Hugo features
    • Static site generators
    • Hugo's security model
    • Hugo and the GDPR
    • License
  • Installation
    • Overview
    • macOS
    • Linux
    • Windows
    • BSD
  • Getting started
    • Overview
    • Quick start
    • Basic usage
    • Directory structure
    • Configuration
    • Configure markup
    • Glossary of terms
    • External learning resources
  • Quick reference
    • Overview
    • Emojis
    • Functions
    • Methods
    • Page collections
  • Content management
    • Overview
    • Organization
    • Page bundles
    • Content formats
    • Front matter
    • Build options
    • Page resources
    • Image processing
    • Shortcodes
    • Related content
    • Sections
    • Content types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and cross references
    • URL management
    • Menus
    • Static files
    • Table of contents
    • Comments
    • Multilingual
    • Markdown attributes
    • Syntax highlighting
    • Diagrams
    • Mathematics
  • Templates
    • Overview
    • Templating
    • Template lookup order
    • Base templates and blocks
    • Single page templates
    • List templates
    • Homepage template
    • Section templates
    • Taxonomy templates
    • Pagination
    • Content view templates
    • Partial templates
    • Shortcode templates
    • Menu templates
    • Data templates
    • RSS templates
    • Sitemap templates
    • Internal templates
    • Custom output formats
    • 404 page
    • Robots.txt
  • Functions
    • Overview
    • cast
    • collections
    • compare
    • crypto
    • data
    • debug
    • diagrams
    • encoding
    • fmt
    • global
    • go template
    • hugo
    • images
    • inflect
    • js
    • lang
    • math
    • openapi3
    • os
    • partials
    • path
    • reflect
    • resources
    • safe
    • strings
    • templates
    • time
    • transform
    • urls
  • Methods
    • Overview
    • Duration
    • Menu
    • Menu entry
    • Page
    • Pages
    • Resource
    • Shortcode
    • Site
    • Taxonomy
    • Time
  • Render hooks
    • Overview
    • Introduction
    • Code blocks
    • Headings
    • Images
    • Links
  • Hugo Modules
    • Overview
    • Configure Hugo modules
    • Use Hugo Modules
    • Theme components
  • Hugo Pipes
    • Overview
    • Introduction
    • Transpile Sass to CSS
    • PostCSS
    • PostProcess
    • JavaScript building
    • Babel
    • Asset minification
    • Concatenating assets
    • Fingerprinting and SRI hashing
    • Resource from string
    • Resource from template
  • CLI
  • Troubleshooting
    • Overview
    • Audit
    • Logging
    • Inspection
    • Deprecation
    • Performance
    • FAQs
  • Developer tools
    • Overview
    • Editor plugins
    • Front-ends
    • Search
    • Migrations
    • Other projects
  • Hosting and deployment
    • Overview
    • Hugo Deploy
    • Deploy with Rclone
    • Deploy with Rsync
    • Host on 21YunBox
    • Host on AWS Amplify
    • Host on Azure Static Web Apps
    • Host on Cloudflare Pages
    • Host on Firebase
    • Host on GitHub Pages
    • Host on GitLab Pages
    • Host on KeyCDN
    • Host on Netlify
    • Host on Render
  • Contribute
    • Overview
    • Development
    • Documentation
    • Themes
  • Maintenance
TEMPLATES

Lists of content in Hugo

Lists have a specific meaning and usage in Hugo when it comes to rendering your site homepage, section page, taxonomy list, or taxonomy terms list.

What is a list page template?

A list page template is a template used to render multiple pieces of content in a single HTML page. The exception to this rule is the homepage, which is still a list but has its own dedicated template.

Hugo uses the term list in its truest sense; i.e. a sequential arrangement of material, especially in alphabetical or numerical order. Hugo uses list templates on any output HTML page where content is traditionally listed:

  • Home page
  • Section pages
  • Taxonomy pages
  • Taxonomy term pages
  • RSS feeds
  • Sitemaps

For template lookup order, see Template Lookup.

The idea of a list page comes from the hierarchical mental model of the web and is best demonstrated visually:

Image demonstrating a hierarchical website sitemap.

List defaults

Default templates

Since section lists and taxonomy lists (N.B., not taxonomy terms lists) are both lists with regards to their templates, both have the same terminating default of _default/list.html or themes/<THEME>/layouts/_default/list.html in their lookup order. In addition, both section lists and taxonomy lists have their own default list templates in _default.

See Template Lookup Order for the complete reference.

Add content and front matter to list pages

Since v0.18, everything in Hugo is a Page. This means list pages and the homepage can have associated content files (i.e. _index.md) that contain page metadata (i.e., front matter) and content.

This new model allows you to include list-specific front matter via .Params and also means that list templates (e.g., layouts/_default/list.html) have access to all page variables.

It is important to note that all _index.md content files will render according to a list template and not according to a single page template.

Example project directory

The following is an example of a typical Hugo project directory’s content:

.
...
├── content
|   ├── posts
|   |   ├── _index.md
|   |   ├── post-01.md
|   |   └── post-02.md
|   └── quote
|   |   ├── quote-01.md
|   |   └── quote-02.md
...

Using the above example, let’s assume you have the following in content/posts/_index.md:

content/posts/_index.md
---
title: My Go Journey
date: 2017-03-23
publishdate: 2017-03-24
---

I decided to start learning Go in March 2017.

Follow my journey through this new blog.

You can now access this _index.md’s’ content in your list template:

layouts/_default/list.html
{{ define "main" }}
  <main>
    <article>
      <header>
        <h1>{{ .Title }}</h1>
      </header>
      <!-- "{{ .Content }}" pulls from the Markdown content of the corresponding _index.md -->
      {{ .Content }}
    </article>
    <ul>
      <!-- Ranges through content/posts/*.md -->
      {{ range .Pages }}
        <li>
          <a href="{{ .RelPermalink }}">{{ .Date.Format "2006-01-02" }} | {{ .LinkTitle }}</a>
        </li>
      {{ end }}
    </ul>
  </main>
{{ end }}

This above will output the following HTML:

example.com/posts/index.html
<!--top of your baseof code-->
<main>
  <article>
    <header>
      <h1>My Go Journey</h1>
    </header>
    <p>I decided to start learning Go in March 2017.</p>
    <p>Follow my journey through this new blog.</p>
  </article>
  <ul>
    <li><a href="/posts/post-01/">Post 1</a></li>
    <li><a href="/posts/post-02/">Post 2</a></li>
  </ul>
</main>
<!--bottom of your baseof-->

List pages without _index.md

You do not have to create an _index.md file for every list page (i.e. section, taxonomy, taxonomy terms, etc) or the homepage. If Hugo does not find an _index.md within the respective content section when rendering a list template, the page will be created but with no {{ .Content }} and only the default values for .Title etc.

Using this same layouts/_default/list.html template and applying it to the quotes section above will render the following output. Note that quotes does not have an _index.md file to pull from:

example.com/quote/index.html
<!--baseof-->
<main>
  <article>
    <header>
      <!-- Hugo assumes that .Title is the name of the section since there is no _index.md content file from which to pull a "title:" field -->
      <h1>Quotes</h1>
    </header>
  </article>
  <ul>
    <li><a href="https://example.org/quote/quotes-01/">Quote 1</a></li>
    <li><a href="https://example.org/quote/quotes-02/">Quote 2</a></li>
  </ul>
</main>
<!--baseof-->

The default behavior of Hugo is to pluralize list titles; hence the inflection of the quote section to “Quotes” when called with the .Title page variable. You can change this via the pluralizeListTitles directive in your site configuration.

Example list templates

Section template

This list template has been modified slightly from a template originally used in spf13.com. It makes use of partial templates for the chrome of the rendered page rather than using a base template. The examples that follow also use the content view templates li.html or summary.html.

layouts/section/posts.html
{{ partial "header.html" . }}
{{ partial "subheader.html" . }}
<main>
  <div>
    <h1>{{ .Title }}</h1>
    <ul>
      <!-- Renders the li.html content view for each content/posts/*.md -->
      {{ range .Pages }}
        {{ .Render "li" }}
      {{ end }}
    </ul>
  </div>
</main>
{{ partial "footer.html" . }}

Taxonomy template

layouts/_default/taxonomy.html
{{ define "main" }}
<main>
  <div>
    <h1>{{ .Title }}</h1>
    <!-- ranges through each of the content files associated with a particular taxonomy term and renders the summary.html content view -->
    {{ range .Pages }}
      {{ .Render "summary" }}
    {{ end }}
  </div>
</main>
{{ end }}

Sort content

By default, Hugo sorts page collections by:

  1. Page weight
  2. Page date (descending)
  3. Page linkTitle, falling back to page title
  4. Page file path if the page is backed by a file

Change the sort order using any of the methods below.

.ByDate
Returns the given page collection sorted by date in ascending order.
.ByExpiryDate
Returns the given page collection sorted by expiration date in ascending order.
.ByLanguage
Returns the given page collection sorted by language in ascending order.
.ByLastmod
Returns the given page collection sorted by last modification date in ascending order.
.ByLength
Returns the given page collection sorted by content length in ascending order.
.ByLinkTitle
Returns the given page collection sorted by link title in ascending order, falling back to title if link title is not defined.
.ByParam
Returns the given page collection sorted by the given parameter in ascending order.
.ByPublishDate
Returns the given page collection sorted by publish date in ascending order.
.ByTitle
Returns the given page collection sorted by title in ascending order.
.ByWeight
Returns the given page collection sorted by weight in ascending order.
.Reverse
Returns the given page collection in reverse order.

Group content

Group your content by field, parameter, or date using any of the methods below.

.GroupBy
Returns the given page collection grouped by the given field in ascending order.
.GroupByDate
Returns the given page collection grouped by date in descending order.
.GroupByExpiryDate
Returns the given page collection grouped by expiration date in descending order.
.GroupByLastmod
Returns the given page collection grouped by last modification date in descending order.
.GroupByParam
Returns the given page collection grouped by the given parameter in ascending order.
.GroupByParamDate
Returns the given page collection grouped by the given date parameter in descending order.
.GroupByPublishDate
Returns the given page collection grouped by publish date in descending order.
.Reverse
Returns the given page collection in reverse order.

Filtering and limiting lists

Sometimes you only want to list a subset of the available content. A common is to only display posts from main sections on the blog’s homepage.

See the documentation on where and first for further details.

See also

  • Content types
  • Menu templates
  • Pagination
  • Partial templates
  • Section page templates

On this page

  • What is a list page template?
  • List defaults
  • Add content and front matter to list pages
  • Example list templates
  • Sort content
  • Group content
  • Filtering and limiting lists
Last updated: February 11, 2024: Capitalize the word Markdown throughout the documentation (c36d20d3)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 

Hugo Sponsors

 

The Hugo logos are copyright © Steve Francia 2013–2024.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Installation
  • Getting started
  • Quick reference
  • Content management
  • Templates
  • Functions
  • Methods
  • Render hooks
  • Hugo Modules
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Developer tools
  • Hosting and deployment
  • Contribute
  • Maintenance