Layouts
-
HTML Templates.
-
Any folder in
layoutsthat does not start with_represents the root of a Page path . In Hugo v0.146.0 , this can be nested as deeply as needed, and_shortcodesand_markupfolders can be placed at any level in the tree. -
The
layouts/shortcodesfolder is renamed tolayouts/_shortcodes. -
The
layouts/partialsfolder is renamed tolayouts/_partials. -
The
_defaultfolder is removed.-
Move all files in
layouts/_defaultup to thelayouts/root.
-
-
The above also means that there’s no top-level
layouts/taxonomyorlayouts/sectionfolders anymore, unless it represents a Page path .-
Move them up to
layouts/with one of the Page kindssection,taxonomyortermas the base name, or place the layouts into the taxonomy Page path .
-
-
A template named
taxonomy.htmlused to be a candidate for both Page kindtermandtaxonomy, now it’s only considered fortaxonomy.-
Create both
taxonomy.htmlandterm.htmlor create a more general layout, e.g.list.html.
-
-
For base templates (e.g.,
baseof.html), in previous Hugo versions, you could prepend one identifier (layout, type, or kind) with a hyphen in front of the baseof keyword.-
Move that identifier after the first “dot,” e.g., rename
list-baseof.htmltobaseof.list.html.
-
-
We have added a new
all“catch-all” layout. This means that if you have, e.g.,layouts/all.htmland that is the only template, that layout will be used for all HTML page rendering. -
We have removed the concept of
_internalHugo templates. 1-
Replace constructs similar to
{{ template "_internal/opengraph.html" . }}with{{ partial "opengraph.html" . }}.
-
-
The identifiers that can be used in a template filename are one of the Page kinds (
home,page,section,taxonomy, orterm), one of the standard layouts (list,single, orall), a custom layout (as defined in thelayoutfront matter field), a language (e.g.,en), an output format (e.g.,html,rss), and a suffix representing the media type. E.g.,all.en.htmlandhome.rss.xml. -
The above means that there’s no such thing as an
index.htmltemplate for the home page anymore.-
Rename
index.htmltohome.html.
-
Types
-
Base :
-
A base template serves as a foundational layout that other templates can build upon. It typically defines the common structural components of your HTML, such as the
html,head, andbodyelements. It also often includes recurring features like headers, footers, navigation, and script inclusions that appear across multiple pages of your site. -
Hugo can apply a base template to the following template types: home , page , section , taxonomy , term , single , list , and all . When Hugo parses any of these template types, it will apply a base template only if the template being parsed meets these specific conditions:
-
It can only contain
defineactions, whitespace, and template comments . No other content is allowed.
-
If a template doesn’t meet all these criteria, Hugo executes it exactly as provided, without applying a base template.
-
When Hugo applies a base template, it replaces its
blockactions with content from the correspondingdefineactions found in the template to which the base template is applied. -
For example, the base template below calls the
partialfunction to includehead,header, andfooterelements. Theblockaction acts as a placeholder, and its content will be replaced by a matchingdefineaction from the template to which it is applied.
-
-
Home :
-
A home template renders your site’s home page.
-
For example, Hugo applies a base template to the home template, then renders the page content and a list of the site’s regular pages.
-
-
Page :
-
A page template renders a regular page.
-
For example, Hugo applies a base template to the page template, then renders the page title and page content.
-
-
Section :
-
A section template renders a list of pages within a section .
-
For example, Hugo applies a base template to the section template, then renders the page title, page content, and a list of pages in the current section.
-
-
Taxonomy :
-
A taxonomy template renders a list of terms in a taxonomy .
-
For example, Hugo applies a base template to the taxonomy template, then renders the page title, page content, and a list of terms in the current taxonomy.
-
Within a taxonomy template, the
Dataobject provides these taxonomy-specific methods: -
The
Termsmethod returns a taxonomy object , allowing you to call any of its methods includingAlphabeticalandByCount. For example, use theByCountmethod to render a list of terms sorted by the number of pages associated with each term:
-
-
Term :
-
A term template renders a list of pages associated with a term .
-
For example, Hugo applies a base template to the term template, then renders the page title, page content, and a list of pages associated with the current term.
-
Within a term template, the
Dataobject provides these term-specific methods:
-
-
Single :
-
A single template is a fallback for a page template. If a page template does not exist, Hugo will look for a single template instead.
-
For example, Hugo applies a base template to the single template, then renders the page title and page content.
-
-
List :
-
A list template is a fallback for home , section , taxonomy , and term templates. If one of these template types does not exist, Hugo will look for a list template instead.
-
For example, Hugo applies a base template to the list template, then renders the page title, page content, and a list of pages.
-
_index.md.-
It allows you to add front matter and content to
home,section,taxonomy, andtermpages. -
Access the content and metadata within an
_index.mdfile by invoking theGetPagemethod on aSiteorPageobject.
-
-
-
All :
-
An all template is a fallback for home , page , section , taxonomy , term , single , and list templates. If one of these template types does not exist, Hugo will look for an all template instead.
-
For example, Hugo applies a base template to the all template, then conditionally renders a page based on its page kind.
-
-
Partial :
-
A partial template is typically used to render a component of your site, though you may also create partial templates that return values.
-
Partials vs Shortcodes :
-
You can Partials in Templates.
-
You can Shortcodes in files.
-
(( partial "header" . ))-
The
.represents the scope of what you want to access. -
"header"is the name of the partial template, located aslayouts/partial/header.html.
-
Lookup Order
| Identifier | Description |
|----------------------------------------------------|-----------------------------------------------------------------------------------------------|
| Layout custom | The custom
layout
set in front matter. |
|
Page kinds
| One of
home
,
section
,
taxonomy
,
term
,
page
. |
| Layouts standard 1 |
list
or
single
. |
| Output format | The output format (e.g.,
html
,
rss
). |
| Layouts standard 2 |
all
. |
| Language | The language (e.g.,
en
). |
| Media type | The media type (e.g.,
text/html
). |
|
Page path
| The page path (e.g.,
/blog/mypost
). |
| Type |
type
set in front matter.
2
|
Shortcodes
-
Predefined chunks of HTML code that you can insert into the markdown files.
-
((< shortcode-name param1 >)) -
Hugo comes will some shortcodes predefined:
-
((< youtube j11Nm4i4XbI >))-
This is the id for the youtube video of oppenheimer ost.
-
-
Emojis
Numbered List / Ordered List
-
.