HUGO
Menu
GitHub 87548 stars Mastodon

Name

返回 shortcode 文件名,不包括文件擴展名。

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' argument. See %s" .Name .Position }}
{{ end }}

在缺少 “greeting” 參數的情況下,Hugo 將拋出錯誤消息並使構建失敗:

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

Last updated: January 1, 0001
Improve this page