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"位置计算可能开销较大。限制其使用于错误报告。