The template lookup
website-generator performs a check to see which template should be loaded for a Markdown file.
The current directory, file name and content type (i.e. page or section) are used to determine which template file to use.
The lookup is performed in reverse, checking for the existence of the most specific template that would apply and working backwards until it either:
- finds a matching template; or
- uses the base template as the default.
A template lookup is performed for pages, sections and the home page.
Examples of template lookup
The home page
The home page Markdown file in content/_index.md will have the following
template lookup:
templates/_index.hbstemplates/section.hbstemplates/base.hbs
Pages
A Markdown file in content/my-page.md will have the following template lookup:
templates/my-page.hbstemplates/page.hbstemplates/_base.hbs
There is a known limitation where content/page.md will conflict with the
generic templates/page.hbs template. As a workaround, the url front
matter can be used to set the URL as
build/page/index.html while renaming the file to content/_page.md.
A Markdown file in content/section/my-page.md will have the following template
lookup:
templates/section/my-page.hbstemplates/section/page.hbstemplates/my-page.hbstemplates/page.hbstemplates/_base.hbs
A Markdown file in content/my-section/nested-section/my-page.md will have the
following template lookup:
templates/my-section/nested-section/my-page.hbstemplates/my-section/nested-section/page.hbstemplates/my-section/my-page.hbstemplates/my-section/page.hbstemplates/my-page.hbstemplates/page.hbstemplates/_base.hbs
This process is repeated for all further nested sections.
Sections
A Markdown file in content/my-section/_index.md will have the following
template lookup:
templates/my-section/section.hbstemplates/section.hbstemplates/_base.hbs
A Markdown file in content/my-section/nested-section/_index.md will have the
following template lookup:
templates/my-section/nested-section/section.hbstemplates/my-section/section.hbstemplates/section.hbstemplates/_base.hbs