Skip to content

Instantly share code, notes, and snippets.

@wjkoh
Last active March 11, 2025 11:41
Show Gist options
  • Save wjkoh/1f05a76c8d1b38ed52a14ed6e971497b to your computer and use it in GitHub Desktop.
Save wjkoh/1f05a76c8d1b38ed52a14ed6e971497b to your computer and use it in GitHub Desktop.
html/template: Implicit Double Quotes

In Go's html/template, you don't have to enclose a template action within double quotes. The html/template package automatically adds double quotes to your string.

<span title="{{.Title}}">Hello World</span>
<span title={{.Title}}>Hello World</span>

Both examples produce the same HTML:

<span title="This is title">Hello World</span>

This feature is especially helpful when you need to use double quotes within a template action.

Incorrect:

<span title="{{printf "%0.2f" .Score}}">Score</span>

Correct:

<span title={{printf "%0.2f" .Score}}>Score</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment