Quick actions

cmd+k|ctrl+k

Navigation

Languages

Text and HTML templates / Built-in functions / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:16:46Z

Updated

2019-03-26T10:16:46Z

package main

import (
	"log"
	"os"
	"text/template"
)

const tmplStr = `js escape  : {{ js .JS }}
html escape: {{ html .HTML }}
url escape : {{ urlquery .URL }}
`

func main() {
	t := template.Must(template.New("print").Parse(tmplStr))

	data := struct {
		JS   string
		HTML string
		URL  string
	}{
		JS:   `function me(s) { return "foo"; }`,
		HTML: `<div>text</div>`,
		URL:  `http://www.programming-books.io`,
	}
	err := t.Execute(os.Stdout, data)
	if err != nil {
		log.Fatalf("t.Execute() failed with '%s'\n", err)
	}
}
INFO