templates.Exists
Reports whether a template file exists under the given path relative to the layouts directory.
- Syntax
- templates.Exists PATH
- Returns
- bool
Usage
The templates.Exists function reports whether a template file exists under the given path relative to the layouts directory. Include the file extension in PATH, such as _partials/footer.html.
The function searches the layouts directory of the unified file system and the embedded templates.
Use this function to check for a template before calling it, such as when you build the template path from page data.
Examples
{{ $partialPath := printf "headers/%s.html" .Type }}
{{ if templates.Exists (printf "_partials/%s" $partialPath) }}
{{ partial $partialPath . }}
{{ else }}
{{ partial "headers/default.html" . }}
{{ end }}Last updated:
November 8, 2026
:
content: Remove categories from front matter (1cc1dd83a)
Improve this page