raymond.go 853 B

12345678910111213141516171819202122232425262728
  1. // Package raymond provides handlebars evaluation
  2. package raymond
  3. // Render parses a template and evaluates it with given context
  4. //
  5. // Note that this function call is not optimal as your template is parsed everytime you call it. You should use Parse() function instead.
  6. func Render(source string, ctx interface{}) (string, error) {
  7. // parse template
  8. tpl, err := Parse(source)
  9. if err != nil {
  10. return "", err
  11. }
  12. // renders template
  13. str, err := tpl.Exec(ctx)
  14. if err != nil {
  15. return "", err
  16. }
  17. return str, nil
  18. }
  19. // MustRender parses a template and evaluates it with given context. It panics on error.
  20. //
  21. // Note that this function call is not optimal as your template is parsed everytime you call it. You should use Parse() function instead.
  22. func MustRender(source string, ctx interface{}) string {
  23. return MustParse(source).MustExec(ctx)
  24. }