-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
53 lines (40 loc) · 1.11 KB
/
README
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
Implements nested templates in Go.
Uses the template package, but allows for nested templates.
Install:
goinstall github.com/yohcop/ntemplate.go/ntemplate
Example of use:
import "github.com/yohcop/ntemplate.go/ntemplate"
// ...
// Create a configuration, specifies the base dir, and if the templates
// files should be cached.
conf := &Config{Basedir: "testdata", Cache: false}
// Create a template that will be nested
nested := conf.Template("nested.tpl")
// And set some values.
nested.Vars["var1"] = []string{"Nested", "Simple", "Useful"}
// Create the parent template
a := conf.Template("main.tpl")
// Add the nested template, and some more values.
a.Vars["child"] = nested
a.Vars["s1"] = "Hello"
a.Vars["s2"] = "Thanks, Bye!"
// Finally, render the template.
s, _ := a.Render()
nested.tpl:
They are:
{.repeated section var1}
- {@},
{.end}
main.tpl:
{s1} Nested Templates,
{child}
{s2}
Expected output:
Hello Nested Templates,
They are:
- Nested,
- Simple,
- Useful,
Thanks, Bye!
Known issues:
It seems that some new lines are inserted after the template variables. Will investigate.