位置
语法
SHORTCODE.Position
返回
text.Position
Position
方法对于错误报告非常有用。例如,如果你的短代码需要一个“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"