Position
返回調用 shortcode 的文件名和位置。
Syntax
SHORTCODE.Position
Returns
text.Position
Position 方法對於錯誤報告很有用。例如,如果您的 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"位置計算可能開銷較大。限制其使用於錯誤報告。