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