參數
當您使用位置參數調用短代碼時,Params
方法會返回一個切片。
content/about.md
{{< myshortcode "Hello" "world" >}}
layouts/shortcodes/myshortcode.html
{{ index .Params 0 }} → Hello
{{ index .Params 1 }} → world
當您使用命名參數調用短代碼時,Params
方法會返回一個映射。
content/about.md
{{< myshortcode greeting="Hello" name="world" >}}
layouts/shortcodes/myshortcode.html
{{ .Params.greeting }} → Hello
{{ .Params.name }} → world