]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: add an example for the Delims method
authorDmitry Neverov <dmitry.neverov@gmail.com>
Thu, 30 Aug 2018 18:58:31 +0000 (20:58 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 30 Aug 2018 19:36:15 +0000 (19:36 +0000)
Change-Id: I7ba55e3f6ebbaae41188316a66a40f994c037ad9
Reviewed-on: https://go-review.googlesource.com/132240
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/html/template/example_test.go

index 3fc982054ef60e45570f51a42347873ed7162c90..533c0dd9616a022b852a872708c351d10e525785 100644 (file)
@@ -123,6 +123,28 @@ func Example_escape() {
 
 }
 
+func ExampleTemplate_Delims() {
+       const text = "<<.Greeting>> {{.Name}}"
+
+       data := struct {
+               Greeting string
+               Name     string
+       }{
+               Greeting: "Hello",
+               Name:     "Joe",
+       }
+
+       t := template.Must(template.New("tpl").Delims("<<", ">>").Parse(text))
+
+       err := t.Execute(os.Stdout, data)
+       if err != nil {
+               log.Fatal(err)
+       }
+
+       // Output:
+       // Hello {{.Name}}
+}
+
 // The following example is duplicated in text/template; keep them in sync.
 
 func ExampleTemplate_block() {