mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 04:44:38 -04:00
Clarify .Page.File behavior when page is not backed by a file
This commit is contained in:
parent
cab417dee3
commit
3af715f779
@ -22,7 +22,9 @@ content/
|
|||||||
└── book-2.md
|
└── book-2.md
|
||||||
```
|
```
|
||||||
|
|
||||||
Code defensively by verifying file existence as shown in each of the examples below.
|
{{% note %}}
|
||||||
|
Code defensively by verifying file existence as shown in the examples below.
|
||||||
|
{{% /note %}}
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
@ -171,13 +173,7 @@ Some of the pages on a site may not be backed by a file. For example:
|
|||||||
- Taxonomy pages
|
- Taxonomy pages
|
||||||
- Term pages
|
- Term pages
|
||||||
|
|
||||||
Without a backing file, Hugo will throw a warning if you attempt to access a `.File` property. For example:
|
Without a backing file, Hugo will throw an error if you attempt to access a `.File` property. To code defensively, first check for file existence:
|
||||||
|
|
||||||
```text
|
|
||||||
WARN .File.ContentBaseName on zero object. Wrap it in if or with...
|
|
||||||
```
|
|
||||||
|
|
||||||
To code defensively, first check for file existence:
|
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
{{ with .File }}
|
{{ with .File }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user