// RenderHTML creates a new template and applies a parsed template to the specified
// data object. For function, Tf is available by default and if you want to add functions
//to your template, just add them to funcs which will add them to the template with their
// original function names. If you added anonymous functions, they will be available in your
// templates as func1, func2 ...etc.
RenderHTML creates a new template and applies a parsed template to the specified
data object. For function, Tf is available by default and if you want to add functions
to your template, just add them to funcs which will add them to the template with their
original function names. If you added anonymous functions, they will be available in your
templates as func1, func2 ...etc.
// RenderHTML creates a new template and applies a parsed template to the specified // data object . For function Tf is available by default and if you want to add functions // to your template just add them to funcs which will add them to the template with their // original function names . If you added anonymous functions they will be available in your // templates as func1 func2 ... etc .
func RenderHTMLAsString(writer *bytes.Buffer, path string, data interface{}, baseFuncMap template.FuncMap, funcs ...template.FuncMap) error {
	var err error
	var funcs1 template.FuncMap
	if len(funcs) == 0 {
		funcs1 = make(template.FuncMap)
	} else {
		funcs1 = funcs[0]
	}
	for k, v := range baseFuncMap {
		funcs1[k] = v
	}
	for k, v := range FuncMap {
		_, funcExists := funcs1[k]
		if !funcExists {
			funcs1[k] = v
		}
	}
	 else {
	templateNameParts := strings.Split(path, "/")
	templateContent := CurrentConfig.GetTemplateContent(path)
	newT, err := template.New(templateNameParts[len(templateNameParts)-1]).Funcs(funcs1).Parse(
		string(templateContent),
	)
	if err != nil {
		Trail(ERROR, "RenderHTML unable to parse %s. %s", path, err)
		return err
	}
	err = newT.Execute(writer, data)
	if err != nil {
		Trail(ERROR, "RenderHTML unable to parse %s. %s", path, err)
		return err
	}
	return nil
}
func RenderHTMLAsString ( writer * bytes . Buffer , path string , data interface { } , baseFuncMap template . FuncMap , funcs ... template . FuncMap ) error { var err error var funcs1 template . FuncMap if len ( funcs ) == 0 { funcs1 = make ( template . FuncMap ) } else { funcs1 = funcs [ 0 ] } for k , v := range baseFuncMap { funcs1 [ k ] = v } for k , v := range FuncMap { _ , funcExists := funcs1 [ k ] if ! funcExists { funcs1 [ k ] = v } } templateNameParts := strings . Split ( path , " " ) templateContent := CurrentConfig . GetTemplateContent ( path ) newT , err := template . New ( templateNameParts [ len ( templateNameParts ) - 1 ] ) . Funcs ( funcs1 ) . Parse ( string ( templateContent ) , ) if err != nil { Trail ( ERROR , " " , path , err ) return err } err = newT . Execute ( writer , data ) if err != nil { Trail ( ERROR , " " , path , err ) return err } return nil }
RenderHTML creates a new template and applies a parsed template to the specified
data object.
RenderHTML creates a new template and applies a parsed template to the specified data object .
//Include := func(funcs1 template.FuncMap) func (templateName string, data1 ...interface{}) string { //	return func (templateName string, data1 ...interface{}) string { //		templateWriter := bytes.NewBuffer([]byte{}) //		data2 := data //		if len(data1) == 1 { //			data2 = data1[0] //		} //		err := RenderHTMLAsString(templateWriter, fsys, CurrentConfig.GetPathToTemplate(templateName), data2, baseFuncMap, funcs1) //		if err != nil { //			Trail(CRITICAL, "Error while parsing include of the template %s", templateName) //			panic(err) //		} //		return templateWriter.String() //	} //} //includeToKeep, includeToKeepExists := funcs1["IncludeToKeep"] //if includeToKeepExists { //	funcs1["Include"] = includeToKeep //	// delete(funcs1, "IncludeToKeep") //} else { //	funcs1["Include"] = Include(funcs1) //} //// Check for ABTesting cookie //if cookie, err := ctx.Cookie("abt"); err != nil || cookie == nil { //	now := time.Now().AddDate(0, 0, 1) //	cookie1 := &http.Cookie{ //		Name:    "abt", //		Value:   fmt.Sprint(now.Second()), //		Path:    "/", //		Expires: time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()), //	} //	http.SetCookie(ctx.Writer, cookie1) //} // ctx.AbortWithStatus(500) // ctx.AbortWithStatus(500)