Position
Returns the file name and position from which the shortcode was called.
- Syntax
- SHORTCODE.Position
- Returns
- text.Position
The Position method returns a text.Position object containing the file name, line number, and column number from which the shortcode was called. The text.Position object has its own methods, and you can change how Hugo prints it.
Calculating the position can be expensive, so call this method only when you log an error or warning. 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"Last updated:
November 17, 2026
:
content: Describe Position cost in prose (226546be4)
Improve this page