Quick actions

cmd+k|ctrl+k

Navigation

Languages

Text and HTML templates / HTML templates / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:16:49Z

Updated

2019-03-26T10:16:49Z

package main

import (
	"fmt"
	html_template "html/template"
	"log"
	"os"
	text_template "text/template"
)

const tmplStr = `<div onlick="{{ .JS }}">{{ .HTML }}</div>
`

func main() {
	txt := text_template.Must(text_template.New("text").Parse(tmplStr))

	html := html_template.Must(html_template.New("html").Parse(tmplStr))

	data := struct {
		JS   string
		HTML string
		URL  string
	}{
		JS:   `foo`,
		HTML: `<span>text</span>`,
		URL:  `http://www.programming-books.io`,
	}

	err := txt.Execute(os.Stdout, data)
	if err != nil {
		log.Fatalf("t.Execute() failed with '%s'\n", err)
	}

	fmt.Println()

	err = html.Execute(os.Stdout, data)
	if err != nil {
		log.Fatalf("t.Execute() failed with '%s'\n", err)
	}

}
INFO