Example #1
0
func RenderFileInLayout(filename string, layout string, ctx interface{}) string {
	var application = HelperController{}
	configfilename := "config.toml"
	application.Init(&configfilename)
	template_path := application.Config.Get("general.template_path").(string)
	data, err := ioutil.ReadFile(path.Join(template_path, filename+".hbs"))
	if err != nil {
		glog.Warningf("Can't get template: %v", err)
	}
	tpl, err := raymond.Parse(string(data))
	if err != nil {
		panic(err)
	}
	result, err := tpl.Exec(ctx)
	if err != nil {
		panic(err)
	}
	allCtx, ok := ctx.(map[string]interface{})
	if ok == false {
		//allCtx := map[string]interface{}{}
		glog.Warningf("Empty context")
	}
	allCtx["body"] = result

	layoutData, err := ioutil.ReadFile(path.Join(template_path, layout+".hbs"))
	if err != nil {
		glog.Warningf("Can't get layout template: %v", err)
	}
	layoutTpl, err := raymond.Parse(string(layoutData))
	if err != nil {
		panic(err)
	}
	finalResult, err := layoutTpl.Exec(allCtx)
	if err != nil {
		panic(err)
	}
	return finalResult
}
Example #2
0
func RenderFile(filename string, ctx interface{}) string {
	var application = HelperController{}
	configfilename := "config.toml"
	application.Init(&configfilename)
	template_path := application.Config.Get("general.template_path").(string)
	data, err := ioutil.ReadFile(path.Join(template_path, filename+".hbs"))
	if err != nil {
		glog.Warningf("Can't get template: %v", err)
	}
	tpl, err := raymond.Parse(string(data))
	if err != nil {
		panic(err)
	}
	result, err := tpl.Exec(ctx)
	if err != nil {
		panic(err)
	}
	return result
}