HUGO
Menu
GitHub 87548 stars Mastodon

數據檢查

使用模板函數檢查值和數據結構。

使用 debug.Dump 函數檢查數據結構:

<pre>{{ debug.Dump .Params }}</pre>
{
  "date": "2023-11-10T15:10:42-08:00",
  "draft": false,
  "iscjklanguage": false,
  "lastmod": "2023-11-10T15:10:42-08:00",
  "publishdate": "2023-11-10T15:10:42-08:00",
  "tags": [
    "foo",
    "bar"
  ],
  "title": "My first post"
}

使用 printf 函數(渲染)或 warnf 函數(記錄到控制台)檢查簡單的數據結構。下面的布局字符串同時顯示值和數據類型。

{{ $value := 42 }}
{{ printf "%[1]v (%[1]T)" $value }} → 42 (int)
New in v0.146.0

使用 templates.Current 函數直觀地標記模板執行邊界或顯示模板調用棧。


Last updated: January 1, 0001
Improve this page