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
This example calls a partial template named for the page’s content type if it exists, and calls a default partial template otherwise:
{{ $partialPath := printf "headers/%s.html" .Type }}
{{ if templates.Exists (printf "_partials/%s" $partialPath) }}
{{ partial $partialPath . }}
{{ else }}
{{ partial "headers/default.html" . }}
{{ end }}Last updated:
November 25, 2026
:
content: Add lead-ins to first examples as needed per style guide (5e505b065)
Improve this page