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