-
Notifications
You must be signed in to change notification settings - Fork 36
/
example_macro_test.go
48 lines (44 loc) · 1.04 KB
/
example_macro_test.go
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
package stick_test
import (
"fmt"
"os"
"path/filepath"
"github.com/tyler-sommer/stick"
)
// An example of macro definition and usage.
//
// This example uses a macro to list the values, also showing two
// ways to import macros. Check the templates in the testdata folder
// for more information.
func ExampleEnv_Execute_macro() {
d, _ := os.Getwd()
env := stick.New(stick.NewFilesystemLoader(filepath.Join(d, "testdata")))
params := map[string]stick.Value{
"title_first": "Hello",
"value_first": []struct{ Key, Value string }{
{"item1", "something about item1"},
{"item2", "something about item2"},
},
"title_second": "Responses",
"value_second": []struct{ Key, Value string }{
{"please", "no, thank you"},
{"why not", "cause"},
},
}
err := env.Execute("other.txt.twig", os.Stdout, params)
if err != nil {
fmt.Println(err)
}
// Output:
// Hello
//
// * item1: something about item1 (0)
//
// * item2: something about item2 (1)
//
// Responses
//
// * please: no, thank you (0)
//
// * why not: cause (1)
}