Position
Returns the file name and position from which the shortcode was called.
Syntax
SHORTCODE.Position
Returns
text.Position
The Position
method is useful for error reporting. For example, if your shortcode requires a “greeting” argument:
layouts/shortcodes/myshortcode.html
{{ $greeting := "" }}
{{ with .Get "greeting" }}
{{ $greeting = . }}
{{ else }}
{{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }}
{{ end }}
In the absence of a “greeting” argument, Hugo will throw an error message and fail the build:
ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1"
The position can be expensive to calculate. Limit its use to error reporting.
Last updated:
March 8, 2025
:
content: Replace note shortcode calls with blockquote alerts (c540e6d29)
Improve this page