Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'

This commit is contained in:
Bjørn Erik Pedersen
2023-12-04 15:24:01 +01:00
810 changed files with 24147 additions and 7766 deletions

View File

@@ -1,23 +1,19 @@
---
title: templates.Exists
description: Reports whether a template file exists under the given path relative to the `layouts` directory.
categories: [functions]
description: Reports whether a template file exists under the given path relative to the layouts directory.
categories: []
keywords: []
menu:
docs:
parent: functions
function:
action:
aliases: []
related: []
returnType: bool
signatures: [templates.Exists PATH]
namespace: templates
relatedFunctions: []
aliases: [/functions/templates.exists]
---
A template file is any file living below the `layouts` directories of either the project or any of its theme components including partials and shortcodes.
A template file is any file within the `layouts` directory of either the project or any of its theme components.
The function is particularly handy with dynamic path. The following example ensures the build will not break on a `.Type` missing its dedicated `header` partial.
Use the `templates.Exists` function with dynamic template paths:
```go-html-template
{{ $partialPath := printf "headers/%s.html" .Type }}
@@ -27,3 +23,5 @@ The function is particularly handy with dynamic path. The following example ensu
{{ partial "headers/default.html" . }}
{{ end }}
```
In the example above, if a "headers" partial does not exist for the given content type, Hugo falls back to a default template.

View File

@@ -0,0 +1,13 @@
---
title: Template functions
linkTitle: templates
description:
categories: []
keywords: []
menu:
docs:
identifier: templates-functions
parent: functions
---
Use these functions to query the template system.