mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 11:22:08 -05:00
5fd1e74903
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
1.6 KiB
1.6 KiB
title | linkTitle | description | categories | keywords | menu | weight | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Data inspection | Inspection | Use template functions to inspect values and data structures. |
|
|
40 |
Use the jsonify
function to inspect a data structure:
<pre>{{ jsonify (dict "indent" " ") .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"
}
{{% note %}} Hugo will throw an error if you attempt to use the construct above to display context that includes a page collection. For example, in a home page template, this will fail:
{{ jsonify (dict "indent" " ") . }}
{{% /note %}}
Use the debug.Dump
function to inspect data types:
<pre>{{ debug.Dump .Params }}</pre>
maps.Params{
"date": time.Time{},
"draft": false,
"iscjklanguage": false,
"lastmod": time.Time{},
"publishdate": time.Time{},
"tags": []string{
"foo",
"bar",
},
"title": "My first post",
}
Use the printf
function (render) or warnf
function (log to console) to inspect simple data structures. The layout string below displays both value and data type.
{{ $value := 42 }}
{{ printf "%[1]v (%[1]T)" $value }} → 42 (int)