What's on this Page
- What is a List Page Template?
- List Defaults
- Add Content and Front Matter to List Pages
- Example List Templates
- Order Content
- Group Content
- Filtering and Limiting Lists
Lists of Content in Hugo
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:
- Taxonomy terms pages
- Taxonomy list pages
- Section list pages
- RSS
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:
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 directorys content:
. ... content | posts | | _index.md | | post-01.md | | post-02.md | quote | | quote-01.md | | quote-02.md ...Using the above example, lets assume you have the following in content/posts/_index.md:
You can now access this _index.mds' content in your list template:
This above will output the following HTML:
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:
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.
Taxonomy Template
Order Content
Hugo lists render the content based on metadata you provide in front matter. In addition to sane defaults, Hugo also ships with multiple methods to make quick work of ordering content inside list templates:
Default: Weight > Date > LinkTitle > FilePath
By Weight
Lower weight gets higher precedence. So content with lower weight will come first.
By Date
By Publish Date
By Expiration Date
By Last Modified Date
By Length
By Title
By Link Title
By Parameter
Order based on the specified front matter parameter. Content that does not have the specified front matter field will use the sites .Site.Params default. If the parameter is not found at all in some entries, those entries will appear together at the end of the ordering.
If the targeted front matter field is nested beneath another field, you can access the field using dot notation.
Reverse Order
Reversing order can be applied to any of the above methods. The following uses ByDate as an example:
Group Content
Hugo provides some functions for grouping pages by Section, Type, Date, etc.
By Page Field
In the above example, you may want {{.Title}} to point the title field you have added to your _index.md file instead. You can access this value using the .GetPage function:
By Date
By Publish Date
By Lastmod
By Expiry Date
By Page Parameter
By Page Parameter in Date Format
The following template takes grouping by date a step further and uses Gos layout string. See the Format function for more examples of how to use Gos layout string to format dates in Hugo.
Reverse Key Order
Ordering of groups is performed by keys in alphanumeric order (AZ, 1100) and in reverse chronological order (i.e., with the newest first) for dates.
While these are logical defaults, they are not always the desired order. There are two different syntaxes to change Hugos default ordering for groups, both of which work the same way.
1. Adding the Reverse Method
{{ range (.Pages.GroupBy "Section").Reverse }} {{ range (.Pages.GroupByDate "2006-01").Reverse }}2. Providing the Alternate Direction
{{ range .Pages.GroupByDate "2006-01" "asc" }} {{ range .Pages.GroupBy "Section" "desc" }}Order Within Groups
Because Grouping returns a {{.Key}} and a slice of pages, all of the ordering methods listed above are available.
Here is the ordering for the example that follows:
- Content is grouped by month according to the date field in front matter.
- Groups are listed in ascending order (i.e., the oldest groups first)
- Pages within each respective group are ordered alphabetically according to the title.
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 blogs homepage.
See the documentation on where function and first function for further details.
See Also
- .GetPage
- Content Sections
- Content Types
- Menu Templates
- Pagination
- About Hugo
- Overview
- Hugo's Security Model
- Hugo and GDPR
- What is Hugo
- Hugo Features
- The Benefits of Static
- License
- Getting Started
- Get Started Overview
- Quick Start
- Install Hugo
- Basic Usage
- Directory Structure
- Configuration
- External Learning Resources
- Hugo Modules
- Hugo Modules Overview
- Configure Modules
- Use Hugo Modules
- Theme Components
- Content Management
- 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 and i18n
- Syntax Highlighting
- Templates
- Templates Overview
- Introduction
- Template Lookup Order
- Custom Output Formats
- Base Templates and Blocks
- List Page Templates
- Homepage Template
- Section Templates
- Taxonomy Templates
- Single Page Templates
- Content View Templates
- Data Templates
- Partial Templates
- Shortcode Templates
- Local File Templates
- 404 Page
- Menu Templates
- Pagination
- RSS Templates
- Sitemap Template
- Robots.txt
- Internal Templates
- Alternative Templating
- Template Debugging
- Functions
- Functions Quick Reference
- .AddDate
- .Format
- .Get
- .GetPage
- .HasMenuCurrent
- .IsMenuCurrent
- .Param
- .Render
- .RenderString
- .Scratch
- .Unix
- absLangURL
- absURL
- after
- anchorize
- append
- apply
- base64
- chomp
- complement
- cond
- countrunes
- countwords
- default
- delimit
- dict
- echoParam
- emojify
- eq
- errorf and warnf
- fileExists
- findRE
- first
- float
- ge
- getenv
- group
- gt
- hasPrefix
- highlight
- hmac
- htmlEscape
- htmlUnescape
- hugo
- humanize
- i18n
- Image Functions
- in
- index
- int
- intersect
- isset
- jsonify
- lang
- lang.Merge
- last
- le
- len
- lower
- lt
- markdownify
- Math
- md5
- merge
- ne
- now
- os.Stat
- partialCached
- path.Base
- path.Clean
- path.Dir
- path.Ext
- path.Join
- path.Split
- plainify
- pluralize
- printf
- println
- querify
- range
- readDir
- readFile
- ref
- reflect.IsMap
- reflect.IsSlice
- relLangURL
- relref
- relURL
- replace
- replaceRE
- safeCSS
- safeHTML
- safeHTMLAttr
- safeJS
- safeURL
- seq
- sha
- shuffle
- singularize
- site
- slice
- slicestr
- sort
- split
- string
- strings.Count
- strings.HasSuffix
- strings.Repeat
- strings.RuneCount
- strings.TrimLeft
- strings.TrimPrefix
- strings.TrimRight
- strings.TrimSuffix
- substr
- symdiff
- templates.Exists
- time
- time.Format
- title
- transform.Unmarshal
- trim
- truncate
- union
- uniq
- upper
- urlize
- urls.Parse
- where
- with
- Variables
- Variables Overview
- Site Variables
- Page Variables
- Shortcode Variables
- Pages Methods
- Taxonomy Variables
- File Variables
- Menu Entry Properties
- Hugo Variables
- Git Variables
- Sitemap Variables
- Hugo Pipes
- Hugo Pipes Overview
- Hugo Pipes Introduction
- SASS / SCSS
- PostProcess
- PostCSS
- JavaScript Building
- Babel
- Asset minification
- Asset bundling
- Fingerprinting and SRI
- Resource from Template
- Resource from String
- CLI
- Troubleshooting
- Troubleshoot
- FAQ
- Build Performance
- Tools
- Developer Tools Overview
- Migrations
- Starter Kits
- Frontends
- Editor Plug-ins
- Search
- Other Projects
- Hosting & Deployment
- Hosting & Deployment Overview
- Hugo Deploy
- Host-Agnostic Deploys with Nanobox
- Host on AWS Amplify
- Host on Netlify
- Host on Render
- Host on Firebase
- Host on GitHub
- Host on GitLab
- Hosting on KeyCDN
- Host on Bitbucket
- Deployment with Rsync
- Contribute
- Contribute to Hugo
- Development
- Documentation
- Themes
- Maintenance