From f3fc0090f46b9e1cbcfb5f870d2d0ef59f6e4f31 Mon Sep 17 00:00:00 2001
From: Rob Pike s
.
-The template package is powerful;
+The template package html/template
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 templ.Execute
, in this case the
-form value.
+form value.
Within the template text (templateStr
),
double-brace-delimited pieces denote template actions.
The piece from {{html "{{if .}}"}}
@@ -3005,13 +3005,14 @@ is non-empty.
That is, when the string is empty, this piece of the template is suppressed.
-The snippet {{html "{{urlquery .}}"}}
says to process the data with the function
-urlquery
, which sanitizes the query string
-for safe display on the web page.
+The two snippets {{html "{{.}}"}}
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.
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 documentation +If this is too quick an explanation, see the documentation for the template package for a more thorough discussion.
diff --git a/doc/progs/eff_qr.go b/doc/progs/eff_qr.go index 4ac745c930..861131ddf5 100644 --- a/doc/progs/eff_qr.go +++ b/doc/progs/eff_qr.go @@ -8,9 +8,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 @@ -37,9 +37,9 @@ const templateStr = `
{{if .}} - +