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"