mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit 'b9bd35d72e14932fb6588ff62b90cddef0a060fc' as 'docs'
This commit is contained in:
37
docs/content/en/functions/templates.Exists.md
Normal file
37
docs/content/en/functions/templates.Exists.md
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: templates.Exists
|
||||
linktitle: ""
|
||||
description: "Checks whether a template file exists under the given path relative to the `layouts` directory."
|
||||
godocref: ""
|
||||
date: 2018-11-01
|
||||
publishdate: 2018-11-01
|
||||
lastmod: 2018-11-01
|
||||
categories: [functions]
|
||||
tags: []
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
ns: ""
|
||||
keywords: ["templates", "template", "layouts"]
|
||||
signature: ["templates.Exists PATH"]
|
||||
workson: []
|
||||
hugoversion: "0.46"
|
||||
aliases: []
|
||||
relatedfuncs: []
|
||||
toc: false
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
A template file is any file living below the `layouts` directories of either the project or any of its theme components incudling partials and shortcodes.
|
||||
|
||||
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.
|
||||
|
||||
```go-html-template
|
||||
{{ $partialPath := printf "headers/%s.html" .Type }}
|
||||
{{ if templates.Exists ( printf "partials/%s" $partialPath ) }}
|
||||
{{ partial $partialPath . }}
|
||||
{{ else }}
|
||||
{{ partial "headers/default.html" . }}
|
||||
{{ end }}
|
||||
|
||||
```
|
Reference in New Issue
Block a user