Debian Codegraph @

docs/content/en/methods/shortcode/Position.md

raw
1 ---
2 title: Position
3 description: Returns the file name and position from which the shortcode was called.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: text.Position
9 signatures: [SHORTCODE.Position]
10 ---
11
12 The `Position` method is useful for error reporting. For example, if your shortcode requires a "greeting" argument:
13
14 ```go-html-template {file="layouts/_shortcodes/myshortcode.html"}
15 {{ $greeting := "" }}
16 {{ with .Get "greeting" }}
17 {{ $greeting = . }}
18 {{ else }}
19 {{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }}
20 {{ end }}
21 ```
22
23 In the absence of a "greeting" argument, Hugo will throw an error message and fail the build:
24
25 ```text
26 ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1"
27 ```
28
29 > [!NOTE]
30 > The position can be expensive to calculate. Limit its use to error reporting.