hugo/docs/content/en/methods/shortcode/Name.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

29 lines
844 B
Markdown

---
title: Name
description: Returns the shortcode file name, excluding the file extension.
categories: []
keywords: []
action:
related:
- methods/shortcode/Position
- functions/fmt/Errorf
returnType: string
signatures: [SHORTCODE.Name]
---
The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
{{< code file=layouts/shortcodes/myshortcode.html >}}
{{ $greeting := "" }}
{{ with .Get "greeting" }}
{{ $greeting = . }}
{{ else }}
{{ errorf "The %q shortcode requires a 'greeting' parameter. See %s" .Name .Position }}
{{ end }}
{{< /code >}}
In the absence of a "greeting" parameter, Hugo will throw an error message and fail the build:
```text
ERROR The "myshortcode" shortcode requires a 'greeting' parameter. See "/home/user/project/content/about.md:11:1"
```