英文:
Golang template: what is in the context?
问题
我想看一下传递到模板中的上下文中有什么内容。
我所做的就是在 HTML 中放置一个点:
{{$.}}
当渲染 HTML 时,我得到的结果是:
{http://localhost:1315/blog/index.xml 0xc08fdf36g0 map[Pages:[]] Blog [] map[] 2016-04-07 15:34:03 -0700 PDT 2016-04-07 15:34:03 -0700 PDT { 0} {/blog/ http://localhost:1315/blog/ } false 0xc0825878d0 {{0 0} 1} <nil>}
我知道在 .
中有 .Site
,但它甚至在渲染的 HTML 中都没有显示出来。我如何以更易理解的形式获取上下文,以便在不预先知道它应该具有的所有属性的情况下查看它是什么?
英文:
I want to see what is in the context that is passed into the template.
What I do is basically putting the dot right there in the HTML.:
{{$.}}
What I get back when the HTML is rendered is:
{http://localhost:1315/blog/index.xml 0xc08fdf36g0 map[Pages:[]] Blog [] map[] 2016-04-07 15:34:03 -0700 PDT 2016-04-07 15:34:03 -0700 PDT { 0} {/blog/ http://localhost:1315/blog/ } false 0xc0825878d0 {{0 0} 1} <nil>}
I know for example there is .Site
inside .
but it doesn't even show up in the rendered HTML. How can I get the context in a more understandable form so I can see what it is without previously knowing all the attributes it is supposed to have?
答案1
得分: 5
应该打印出变量名和值。
英文:
{{ printf "%#v" . }}
Should print out the variable name and value.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论