-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_execute_test.go
More file actions
58 lines (49 loc) · 1.02 KB
/
Copy pathexample_execute_test.go
File metadata and controls
58 lines (49 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package apitpl_test
import (
"bytes"
"embed"
"io/fs"
"html/template"
"log"
"os"
"github.com/apisite/apitpl"
"github.com/apisite/apitpl/lookupfs"
"github.com/apisite/apitpl/samplemeta"
)
//go:embed testdata/*
var embedFS embed.FS
// Render template with layout
func Example_execute() {
// BufferPool size for rendered templates
const bufferSize int = 64
cfg := lookupfs.Config{
Includes: "inc_minimal",
Layouts: "layouts",
Pages: "pages",
Ext: ".html",
DefLayout: "default",
}
embedDirFS,_ := fs.Sub(embedFS, "testdata")
tfs, err := apitpl.New(bufferSize).
LookupFS(lookupfs.New(cfg).
FileSystem(embedDirFS)).
Parse()
if err != nil {
log.Fatal(err)
}
var b bytes.Buffer
page := &samplemeta.Meta{}
page.SetLayout("default")
err = tfs.Execute(&b, "subdir3/page", template.FuncMap{}, page)
if err != nil {
log.Fatal(err)
}
_, err = b.WriteTo(os.Stdout)
if err != nil {
log.Fatal(err)
}
// Output:
// <title>Template title</title>
// ==
// page2 here (inc2 here)==inc1
}