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