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