| 1 |
--- |
| 2 |
title: reflect.IsImageResource |
| 3 |
description: Reports whether the given value is a Resource object representing an image as defined by its media type. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: bool |
| 10 |
signatures: [reflect.IsImageResource INPUT] |
| 11 |
--- |
| 12 |
|
| 13 |
{{< new-in 0.154.0 />}} |
| 14 |
|
| 15 |
## Usage |
| 16 |
|
| 17 |
This example iterates through all project resources and uses `reflect.IsImageResource` to decide whether to render an image tag or provide a download link for non-image files. |
| 18 |
|
| 19 |
```go-html-template |
| 20 |
{{ range resources.Match "**" }} |
| 21 |
{{ if reflect.IsImageResource . }} |
| 22 |
<img src="{{ .RelPermalink }}" alt="Image"> |
| 23 |
{{ else }} |
| 24 |
<a href="{{ .RelPermalink }}">Download</a> |
| 25 |
{{ end }} |
| 26 |
{{ end }} |
| 27 |
``` |
| 28 |
|
| 29 |
{{% include "/_common/functions/reflect/image-reflection-functions.md" %}} |