hugo/docs/content/en/methods/shortcode/Name.md
2023-12-04 15:24:01 +01:00

844 B

title description categories keywords action
Name Returns the shortcode file name, excluding the file extension.
related returnType signatures
methods/shortcode/Position
functions/fmt/Errorf
string
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:

ERROR The "myshortcode" shortcode requires a 'greeting' parameter. See "/home/user/project/content/about.md:11:1"