HUGO
Menu
GitHub 87548 stars Mastodon

Get

返回給定參數的值。

Syntax

SHORTCODE.Get ARG

Returns

any

按位置或按名稱指定參數。在 Markdown 中調用 shortcode 時,使用位置參數或命名參數,但不能同時使用兩者。

一些 shortcode 支持位置參數,一些支持命名參數,另一些兩者都支持。有關使用詳情,請參閱 shortcode 的文檔。

位置參數

此 shortcode 調用使用位置參數:

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

要按位置檢索參數:

layouts/_shortcodes/myshortcode.html
{{ printf "%s %s." (.Get 0) (.Get 1) }} → Hello world.

命名參數

此 shortcode 調用使用命名參數:

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

要按名稱檢索參數:

layouts/_shortcodes/myshortcode.html
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} → Hello world.

參數名區分大小寫。


Last updated: January 1, 0001
Improve this page