Skip to content

Commit

Permalink
Clarify .Page.File behavior when page is not backed by a file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored Mar 11, 2024
1 parent cab417d commit 3af715f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions content/en/methods/page/File.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ content/
└── 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

Expand Down Expand Up @@ -171,13 +173,7 @@ Some of the pages on a site may not be backed by a file. For example:
- Taxonomy pages
- Term pages

Without a backing file, Hugo will throw a warning if you attempt to access a `.File` property. For example:

```text
WARN .File.ContentBaseName on zero object. Wrap it in if or with...
```

To code defensively, first check for file existence:
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:

```go-html-template
{{ with .File }}
Expand Down

0 comments on commit 3af715f

Please sign in to comment.