| 1 |
--- |
| 2 |
title: IsNamedParams |
| 3 |
description: Reports whether the shortcode call uses named arguments. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: bool |
| 9 |
signatures: [SHORTCODE.IsNamedParams] |
| 10 |
--- |
| 11 |
|
| 12 |
To support both positional and named arguments when calling a shortcode, use the `IsNamedParams` method to determine how the shortcode was called. |
| 13 |
|
| 14 |
With this _shortcode_ template: |
| 15 |
|
| 16 |
```go-html-template {file="layouts/_shortcodes/myshortcode.html"} |
| 17 |
{{ if .IsNamedParams }} |
| 18 |
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} |
| 19 |
{{ else }} |
| 20 |
{{ printf "%s %s." (.Get 0) (.Get 1) }} |
| 21 |
{{ end }} |
| 22 |
``` |
| 23 |
|
| 24 |
Both of these calls return the same value: |
| 25 |
|
| 26 |
```md {file="content/about.md"} |
| 27 |
{{</* myshortcode greeting="Hello" firstName="world" */>}} |
| 28 |
{{</* myshortcode "Hello" "world" */>}} |
| 29 |
``` |