aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2012-09-22 05:55:11 +1000
committerRob Pike <r@golang.org>2012-09-22 05:55:11 +1000
commitb7f91ba06f79ec5cd278ac8e4a14c5d88130c3f6 (patch)
tree7baa067a55211bf9fbec3187d1aee5c0f58fa5fb
parentfc8f4af6b908808ea91d05cc4bff46343d94e030 (diff)
downloadgo-b7f91ba06f79ec5cd278ac8e4a14c5d88130c3f6.tar.gz
go-b7f91ba06f79ec5cd278ac8e4a14c5d88130c3f6.zip
[release-branch.go1] effective_go: use html/template instead of text/template
««« backport e3fce06291ec effective_go: use html/template instead of text/template Should have done this a long time ago. Fixes #3811. R=golang-dev, adg, rsc CC=golang-dev https://golang.org/cl/6488120 »»»
-rw-r--r--doc/effective_go.html15
-rw-r--r--doc/progs/eff_qr.go6
2 files changed, 11 insertions, 10 deletions
diff --git a/doc/effective_go.html b/doc/effective_go.html
index 6cacac6303..d38b781b45 100644
--- a/doc/effective_go.html
+++ b/doc/effective_go.html
@@ -2992,11 +2992,11 @@ server; it blocks while the server runs.
executes the template on the data in the form value named <code>s</code>.
</p>
<p>
-The template package is powerful;
+The template package <code>html/template</code> is powerful;
this program just touches on its capabilities.
-In essence, it rewrites a piece of text on the fly by substituting elements derived
+In essence, it rewrites a piece of HTML text on the fly by substituting elements derived
from data items passed to <code>templ.Execute</code>, in this case the
-form value.
+form value.
Within the template text (<code>templateStr</code>),
double-brace-delimited pieces denote template actions.
The piece from <code>{{html "{{if .}}"}}</code>
@@ -3005,13 +3005,14 @@ is non-empty.
That is, when the string is empty, this piece of the template is suppressed.
</p>
<p>
-The snippet <code>{{html "{{urlquery .}}"}}</code> says to process the data with the function
-<code>urlquery</code>, which sanitizes the query string
-for safe display on the web page.
+The two snippets <code>{{html "{{.}}"}}</code> say to show the data presented to
+the template—the query string—on the web page.
+The HTML template package automatically provides appropriate escaping so the
+text is safe to display.
</p>
<p>
The rest of the template string is just the HTML to show when the page loads.
-If this is too quick an explanation, see the <a href="/pkg/text/template/">documentation</a>
+If this is too quick an explanation, see the <a href="/pkg/html/template/">documentation</a>
for the template package for a more thorough discussion.
</p>
<p>
diff --git a/doc/progs/eff_qr.go b/doc/progs/eff_qr.go
index de96a0208f..0733bb1637 100644
--- a/doc/progs/eff_qr.go
+++ b/doc/progs/eff_qr.go
@@ -2,9 +2,9 @@ package main
import (
"flag"
+ "html/template"
"log"
"net/http"
- "text/template"
)
var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18
@@ -31,9 +31,9 @@ const templateStr = `
</head>
<body>
{{if .}}
-<img src="http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl={{urlquery .}}" />
+<img src="http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl={{.}}" />
<br>
-{{html .}}
+{{.}}
<br>
<br>
{{end}}