// Takes the care of rendering templates, with an explicit status code.
Takes the care of rendering templates, with an explicit status code.
// Takes the care of rendering templates with an explicit status code .
func (mr *Renderer) RenderTemplatesCode(w http.ResponseWriter, r *http.Request, code int, data map[string]interface{}, tpls ...string) {
	if len(tpls) < 1 {
		w.WriteHeader(500)
		w.Write([]byte("Error: Template required!"))
		return
	}
	defaults := make(map[string]interface{})
	if mr.configer != nil {
		defaults["config"] = mr.configer
	}
	for k, v := range data {
		defaults[k] = v
	}
	list := make([]string, 0)
	for _, elem := range tpls {
		list = append(list, filepath.Join(mr.tplDir, elem))
	}
	if tpl, loadErr := mr.acquireTemplate(strings.Join(tpls, ""), list...); loadErr != nil {
		w.WriteHeader(500)
		w.Write([]byte(loadErr.Error()))
	} else {
		var doc bytes.Buffer
		err := tpl.Execute(&doc, defaults)
		if err == nil {
			w.WriteHeader(code)
			w.Write(doc.Bytes())
		} else {
			w.WriteHeader(500)
			w.Write([]byte(err.Error()))
		}
	}
}
func ( mr * Renderer ) RenderTemplatesCode ( w http . ResponseWriter , r * http . Request , code int , data map [ string ] interface { } , tpls ... string ) { if len ( tpls ) < 1 { w . WriteHeader ( 500 ) w . Write ( [ ] byte ( " " ) ) return } defaults := make ( map [ string ] interface { } ) if mr . configer != nil { defaults [ " " ] = mr . configer } for k , v := range data { defaults [ k ] = v } list := make ( [ ] string , 0 ) for _ , elem := range tpls { list = append ( list , filepath . Join ( mr . tplDir , elem ) ) } if tpl , loadErr := mr . acquireTemplate ( strings . Join ( tpls , " " ) , list ... ) ; loadErr != nil { w . WriteHeader ( 500 ) w . Write ( [ ] byte ( loadErr . Error ( ) ) ) } else { var doc bytes . Buffer err := tpl . Execute ( & doc , defaults ) if err == nil { w . WriteHeader ( code ) w . Write ( doc . Bytes ( ) ) } else { w . WriteHeader ( 500 ) w . Write ( [ ] byte ( err . Error ( ) ) ) } } }
Takes the care of rendering templates, with an explicit status code.
Takes the care of rendering templates with an explicit status code .