diff --git a/4.3.md b/4.3.md index 783e889f..52689d00 100644 --- a/4.3.md +++ b/4.3.md @@ -33,6 +33,19 @@ 输出 Hello, ! + +或者使用template.HTML类型 + + import "html/template" + ... + t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`) + err = t.ExecuteTemplate(out, "T", template.HTML("")) + +输出 + + Hello, ! + +转换成template.HTML后,变量的内容也不会被转义 转义的例子: @@ -45,7 +58,7 @@ Hello, <script>alert('you have been pwned')</script>! - + ## links * [目录]() @@ -53,4 +66,4 @@ * 下一节: [防止多次递交表单](<4.4.md>) ## LastModified - * $Id$ \ No newline at end of file + * $Id$