HUGO
Menu
GitHub 90597 stars Mastodon

reflect.IsResource

Reports whether the given value is a Resource object.
Syntax
reflect.IsResource INPUT
Returns
bool
New in v0.154.0

Usage

The reflect.IsResource function reports whether the given value is a Resource object. The function returns true for any resource, regardless of its resource type, and for any Page object.

Examples

These examples use this project structure:

project/
├── assets/
│   ├── a.json
│   ├── b.avif
│   └── c.jpg
└── content/
    └── example/
        ├── index.md
        ├── d.json
        ├── e.avif
        └── f.jpg

Global resources:

layouts/page.html
{{ with resources.Get "a.json" }}
  {{ reflect.IsResource . }} → true
{{ end }}

{{ with resources.Get "b.avif" }}
  {{ reflect.IsResource . }} → true
{{ end }}

{{ with resources.Get "c.jpg" }}
  {{ reflect.IsResource . }} → true
{{ end }}

Page resources:

layouts/page.html
{{ with .Resources.Get "d.json" }}
  {{ reflect.IsResource . }} → true
{{ end }}

{{ with .Resources.Get "e.avif" }}
  {{ reflect.IsResource . }} → true
{{ end }}

{{ with .Resources.Get "f.jpg" }}
  {{ reflect.IsResource . }} → true
{{ end }}

A page:

layouts/page.html
{{ with site.GetPage "/example" }}
  {{ reflect.IsResource . }} → true
{{ end }}