github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/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 := template.New(input)
    14  
    15  	t, err := t.Parse(input)
    16  	if err != nil {
    17  		return "", err
    18  	}
    19  
    20  	bb := &bytes.Buffer{}
    21  	err = t.Execute(bb, data)
    22  	return bb.String(), err
    23  }