Name
Syntax
SHORTCODE.Name
Returns
string
Name
方法在错误报告中非常有用。例如,如果你的 shortcode 需要一个 “greeting” 参数:
layouts/shortcodes/myshortcode.html
{{ $greeting := "" }}
{{ with .Get "greeting" }}
{{ $greeting = . }}
{{ else }}
{{ errorf "The %q shortcode requires a 'greeting' parameter. See %s" .Name .Position }}
{{ end }}
在没有 “greeting” 参数的情况下,Hugo 会抛出错误消息并失败构建:
ERROR The "myshortcode" shortcode requires a 'greeting' parameter. See "/home/user/project/content/about.md:11:1"