github.com/cheikhshift/buffalo@v0.9.5/render/template_engine.go (about)

     1  package render
     2  
     3  import (
     4  	"bytes"
     5  	"html/template"
     6  )
     7  
     8  // TemplateEngine needs to be implemented for a template system to be able to be used with Buffalo.
     9  type TemplateEngine func(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error)
    10  
    11  // GoTemplateEngine implements the TemplateEngine interface for using standard Go templates
    12  func GoTemplateEngine(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error) {
    13  	t, err := template.New(input).Parse(input)
    14  	if err != nil {
    15  		return "", err
    16  	}
    17  	if helpers != nil {
    18  		t = t.Funcs(helpers)
    19  	}
    20  	bb := &bytes.Buffer{}
    21  	err = t.Execute(bb, data)
    22  	return bb.String(), err
    23  }