用於從頁面資源和站點數據中讀取 JSON、TOML、YAML 數據的函數。
成為我們的資助者或贊助商,以支持我們的工作。
該函數接收 key 和 page 參數。
1{{ with partial "base/functions/data" (dict "key" "foobar" "page" .) }}
2 {{/* ... */}}
3{{ end }}
請注意於短代碼中,頁面變量為 .Page。
key| 名稱 | 上下文 | 類型 | 必填 | 默認值 | 版本 | 示例 |
|---|---|---|---|---|---|---|
key | - | string | ✓ | - | - | - |
不帶擴展名的數據文件名稱,點(.)表示路徑分隔符。
page| 名稱 | 上下文 | 類型 | 必填 | 默認值 | 版本 | 示例 |
|---|---|---|---|---|---|---|
page | - | Page | ✓ | - | - | - |
當前頁變量。
以 content/example/index.md 頁面為例,假設 key 為 foo.bar。
| Path |
|---|
/content/example/foo/bar.toml |
/content/example/foo/bar.yaml |
/content/example/foo/bar.yml |
/content/example/foo/bar.json |
/data/foo/bar.toml |
/data/foo/bar.yaml |
/data/foo/bar.yml |
/data/foo/bar.json |