Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add template debugging functions for variables #1042

Closed
wants to merge 1 commit into from
Closed

Add template debugging functions for variables #1042

wants to merge 1 commit into from

Conversation

mdhender
Copy link
Contributor

@mdhender mdhender commented Apr 4, 2015

Template developers frequently need to show variable values while
debugging templates. Issue #1009 requests better support for this.

There are already ways to display information about template
variables. This patch makes it easier for users that don't have
experience working with Go templates.

The printf "%#v" idiom is powerful but requires some knowledge
of Hugo's internal representation of Go value types. Not all
template designers will have that knowledge. The two functions
inspect and typeOf provide a path towards easier to use and
understand printing of variables and values.

The inspect function replaces the printf call. This version
relies on the default string conversion for the result. This
provides a path towards pretty-printing variables and values.

Templates may use typeOf to determine the best formatting
for variables and values. This replaces printf %T.

References #1009

Template developers frequently need to show variable values while
debugging templates. Issue #1009 requests better support for this.

There are already ways to display information about template
variables. This patch makes it easier for users that don't have
experience working with Go templates.

The `printf "%#v"` idiom is powerful but requires some knowledge
of Hugo's internal representation of Go value types. Not all
template designers will have that knowledge. The two functions
`inspect` and `typeOf` provide a path towards easier to use and
understand printing of variables and values.

The `inspect` function replaces the `printf` call. This version
relies on the default `string` conversion for the result. This
provides a path towards pretty-printing variables and values.

Templates may use `typeOf` to determine the best formatting
for variables and values. This replaces `printf %T`.

References #1009
@bep
Copy link
Member

bep commented Apr 4, 2015

This is a big maybe in my book. Both of these could be replaced with printf. I don't think we should duplicate existing functionality.

If some of that is hard to use, we should document it. I think people would be really happy to know that the powers of printf is available.

@bep
Copy link
Member

bep commented Apr 6, 2015

I think the correct way to do this is:

  1. Add a new DebugEnabled flag (default false)
  2. Add an internal partial that, if DebugEnabled, dumps the context into a HTML table

This way the users can chose where to put this info.

@bep
Copy link
Member

bep commented Jul 25, 2015

I'm closing this now. The thought behind this one is excellent -- but I'm not seeing anything here that isn't possible with printf.

@bep bep closed this Jul 25, 2015
@mdhender mdhender deleted the i01009-add-debug-functions-sorted-003 branch November 30, 2016 06:05
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants