Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute(ctx context.Context, wr io.Writer, name string, data interface{}, opts ...render.Option) error
Example ¶
package main import ( "context" html "html/template" "log" "os" "gitoa.ru/go-4devs/templating" "gitoa.ru/go-4devs/templating/gohtml" ) type Data struct { Name string } func main() { ctx := context.Background() data := Data{Name: "andrey"} gohtml.Must(html.New("example.html").Parse(`Hello {{ .Name }}!`)) err := templating.Execute(ctx, os.Stdout, "example.html.gohtml", data) if err != nil { log.Fatalln(err) } }
Output: Hello andrey!
Example (Text) ¶
package main import ( "context" "log" "os" text "text/template" "gitoa.ru/go-4devs/templating" "gitoa.ru/go-4devs/templating/gotxt" ) type Data struct { Name string } func main() { ctx := context.Background() data := Data{Name: "<u>text</u>"} gotxt.Must(text.New("example.txt").Parse(`Hello {{ .Name }}!`)) err := templating.Execute(ctx, os.Stdout, "example.txt.gotxt", data) if err != nil { log.Fatalln(err) } }
Output: Hello <u>text</u>!
Example (WithOption) ¶
package main import ( "context" html "html/template" "log" "os" "gitoa.ru/go-4devs/templating" "gitoa.ru/go-4devs/templating/gohtml" "gitoa.ru/go-4devs/templating/render" ) type Data struct { Name string } func main() { ctx := context.Background() data := Data{Name: "<b>world</b>"} gohtml.Must(html.New("example_with_option.html").Parse(`Hello <s>{{ .Name }}</s>!`)) err := templating.Execute(ctx, os.Stdout, "example_with_option.html", data, render.WithEngine(gohtml.Name)) if err != nil { log.Fatalln(err) } }
Output: Hello <s><b>world</b></s>!
Example (WithoutEngine) ¶
package main import ( "context" html "html/template" "log" "os" text "text/template" "gitoa.ru/go-4devs/templating" "gitoa.ru/go-4devs/templating/gohtml" "gitoa.ru/go-4devs/templating/gotxt" ) type Data struct { Name string } func main() { ctx := context.Background() data := Data{Name: "engine"} gotxt.Must(text.New("example_engine.txt").Parse(`Text {{ .Name }}!`)) gohtml.Must(html.New("example_engine.html").Parse(`Html {{ .Name }}!`)) err := templating.Execute(ctx, os.Stdout, "example_engine.html", data) if err != nil { log.Fatalln(err) } }
Output: Html engine!
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.