Debian Codegraph @

docs/content/en/troubleshooting/inspection.md

raw
1 ---
2 title: Data inspection
3 linkTitle: Inspection
4 description: Use template functions to inspect values and data structures.
5 categories: []
6 keywords: []
7 ---
8
9 Use the [`debug.Dump`][] function to inspect a data structure:
10
11 ```go-html-template
12 <pre>{{ debug.Dump .Params }}</pre>
13 ```
14
15 ```text
16 {
17 "date": "2023-11-10T15:10:42-08:00",
18 "draft": false,
19 "iscjklanguage": false,
20 "lastmod": "2023-11-10T15:10:42-08:00",
21 "publishdate": "2023-11-10T15:10:42-08:00",
22 "tags": [
23 "foo",
24 "bar"
25 ],
26 "title": "My first post"
27 }
28 ```
29
30 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.
31
32 ```go-html-template
33 {{ $value := 42 }}
34 {{ printf "%[1]v (%[1]T)" $value }} → 42 (int)
35 ```
36
37 {{< new-in 0.146.0 />}}
38
39 Use the [`templates.Current`][] function to visually mark template execution boundaries or to display the template call stack.
40
41 [`debug.Dump`]: /functions/debug/dump/
42 [`printf`]: /functions/fmt/printf/
43 [`templates.Current`]: /functions/templates/current/
44 [`warnf`]: /functions/fmt/warnf/