[Shortcodes][shortcodes] have access to parameters delimited in the shortcode declaration via [`.Get`][getfunction], page- and site-level variables, and also the following shortcode-specific fields:
+.Name
+: Shortcode name.
+
.Ordinal
: Zero-based ordinal in relation to its parent. If the parent is the page itself, this ordinal will represent the position of this shortcode in the page content.
Inner template.HTML
Page *PageWithoutContent
Parent *ShortcodeWithPage
+ Name string
IsNamedParams bool
// Zero-based ordinal in relation to its parent. If the parent is the page itself,
return "", nil
}
- data := &ShortcodeWithPage{Ordinal: sc.ordinal, posOffset: sc.pos, Params: sc.params, Page: p, Parent: parent}
+ data := &ShortcodeWithPage{Ordinal: sc.ordinal, posOffset: sc.pos, Params: sc.params, Page: p, Parent: parent, Name: sc.name}
if sc.params != nil {
data.IsNamedParams = reflect.TypeOf(sc.params).Kind() == reflect.Map
}
}
-func TestShortcodePosition(t *testing.T) {
+func TestShortcodeVariables(t *testing.T) {
t.Parallel()
assert := require.New(t)
{{< s1 >}}
`).WithTemplatesAdded("layouts/shortcodes/s1.html", `
+Name: {{ .Name }}
{{ with .Position }}
File: {{ .Filename }}
Offset: {{ .Offset }}
filepath.FromSlash("File: content/page.md"),
"Line: 7", "Column: 4", "Offset: 40",
filepath.FromSlash("String: \"content/page.md:7:4\""),
+ "Name: s1",
)
}