mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,24 +3,22 @@ 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]
|
||||
params:
|
||||
functions_and_methods:
|
||||
returnType: string
|
||||
signatures: [SHORTCODE.Name]
|
||||
---
|
||||
|
||||
The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" argument:
|
||||
|
||||
{{< code file=layouts/shortcodes/myshortcode.html >}}
|
||||
```go-html-template {file="layouts/shortcodes/myshortcode.html"}
|
||||
{{ $greeting := "" }}
|
||||
{{ with .Get "greeting" }}
|
||||
{{ $greeting = . }}
|
||||
{{ else }}
|
||||
{{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }}
|
||||
{{ end }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
In the absence of a "greeting" argument, Hugo will throw an error message and fail the build:
|
||||
|
||||
|
Reference in New Issue
Block a user