Skip to content

Instantly share code, notes, and snippets.

@budparr
Last active March 7, 2017 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save budparr/7065ba1c949f9e58342afa2b51fd3828 to your computer and use it in GitHub Desktop.
Save budparr/7065ba1c949f9e58342afa2b51fd3828 to your computer and use it in GitHub Desktop.
{{ printf "%#v" . }}
If you ever need to drill into what is passed to a template, just put this at the top of your template somewhere:
{{ printf "%#v" . }}
Then look at a page generated by that template - that'll print out what the top level object is, and what it's fields are. When I do it with a shortcode template, I get something like this:
&hugolib.ShortcodeWithPage{Params:[]string{"."}, Inner:"", Page:(*hugolib.Page)(0xc2082e4840)}
That tells me there's a .Params value which is a list of strings (that contains a single string which is just the dot character), there's a .Inner value which is a string (which is empty), and a Page value, which is a hugolib.Page (the object you get back with various templates from .Page). You can then modify the template to drill down, so now make the template
{{ printf "%#v" .Page }}
That'll print out what the Page value contains.... which is a huge block of stuff, but you should be able understand it, more or less. Repeat as necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment