package raymond import "fmt" func Example() { source := "

{{title}}

{{body.content}}

" ctx := map[string]interface{}{ "title": "foo", "body": map[string]string{"content": "bar"}, } // parse template tpl := MustParse(source) // evaluate template with context output := tpl.MustExec(ctx) // alternatively, for one shots: // output := MustRender(source, ctx) fmt.Print(output) // Output:

foo

bar

} func Example_struct() { source := `

By {{fullName author}}

{{body}}

Comments

{{#each comments}}

By {{fullName author}}

{{body}}
{{/each}}
` type Person struct { FirstName string LastName string } type Comment struct { Author Person Body string } type Post struct { Author Person Body string Comments []Comment } ctx := Post{ Person{"Jean", "Valjean"}, "Life is difficult", []Comment{ Comment{ Person{"Marcel", "Beliveau"}, "LOL!", }, }, } RegisterHelper("fullName", func(person Person) string { return person.FirstName + " " + person.LastName }) output := MustRender(source, ctx) fmt.Print(output) // Output:
//

By Jean Valjean

//
Life is difficult
// //

Comments

// //

By Marcel Beliveau

//
LOL!
//
} func ExampleRender() { tpl := "

{{title}}

{{body.content}}

" ctx := map[string]interface{}{ "title": "foo", "body": map[string]string{"content": "bar"}, } // render template with context output, err := Render(tpl, ctx) if err != nil { panic(err) } fmt.Print(output) // Output:

foo

bar

} func ExampleMustRender() { tpl := "

{{title}}

{{body.content}}

" ctx := map[string]interface{}{ "title": "foo", "body": map[string]string{"content": "bar"}, } // render template with context output := MustRender(tpl, ctx) fmt.Print(output) // Output:

foo

bar

}