HUGO
Menu
GitHub 87548 stars Mastodon

IsNamedParams

报告 shortcode 调用是否使用命名参数。

Syntax

SHORTCODE.IsNamedParams

Returns

bool

要支持调用 shortcode 时使用位置参数和命名参数,请使用 IsNamedParams 方法来确定 shortcode 是如何调用的。

使用此 shortcode 模板:

layouts/_shortcodes/myshortcode.html
{{ if .IsNamedParams }}
  {{ printf "%s %s." (.Get "greeting") (.Get "firstName") }}
{{ else }}
  {{ printf "%s %s." (.Get 0) (.Get 1) }}
{{ end }}

这两个调用都返回相同的值:

content/about.md
{{< myshortcode greeting="Hello" firstName="world" >}}
{{< myshortcode "Hello" "world" >}}

Last updated: January 1, 0001
Improve this page