{{title}}
{{body}}
package raymond import ( "fmt" "testing" ) var sourceBasic = `
{{body.content}}
" ctx := map[string]interface{}{ "title": "foo", "body": map[string]string{"content": "bar"}, } // parse template tpl := MustParse(source) // evaluate template with context output, err := tpl.Exec(ctx) if err != nil { panic(err) } fmt.Print(output) // Output:bar
} func ExampleTemplate_MustExec() { source := "{{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) fmt.Print(output) // Output:bar
} func ExampleTemplate_ExecWith() { source := "{{#body}}{{content}} and {{@baz.bat}}{{/body}}
" ctx := map[string]interface{}{ "title": "foo", "body": map[string]string{"content": "bar"}, } // parse template tpl := MustParse(source) // computes private data frame frame := NewDataFrame() frame.Set("baz", map[string]string{"bat": "unicorns"}) // evaluate template output, err := tpl.ExecWith(ctx, frame) if err != nil { panic(err) } fmt.Print(output) // Output:bar and unicorns
} func ExampleTemplate_PrintAST() { source := "{{#body}}{{content}} and {{@baz.bat}}{{/body}}
" // parse template tpl := MustParse(source) // print AST output := tpl.PrintAST() fmt.Print(output) // Output: CONTENT[ '' ] // BLOCK: // PATH:body [] // PROGRAM: // {{ PATH:content [] // }} // CONTENT[ ' and ' ] // {{ @PATH:baz/bat [] // }} // CONTENT[ '
' ] // }