func newTemplate(app *App, fs vfs.VFS, manager *assets.Manager) *Template { t := &Template{tmpl: template.New(fs, manager), app: app} if app.cfg != nil { t.tmpl.Debug = app.cfg.TemplateDebug } t.tmpl.Funcs(templateFuncs).Funcs([]*template.Func{ {Name: "reverse", Fn: t.reverse, Traits: template.FuncTraitPure}, }) return t }
func ReloadPlugin() *template.Plugin { reload := template.New(devassets.AssetsFS, nil) if err := reload.Parse("reload.html"); err != nil { panic(err) } return &template.Plugin{ Template: reload, Position: assets.Bottom, } }
// LoadTemplatePlugin loads the template from name, using the app templates VFS and // assets manager, and then adds it as a plugin at the given position. // See also App.AddTemplatePlugin. func (app *App) LoadTemplatePlugin(name string, pos assets.Position) error { tmpl := template.New(app.templatesFS, app.assetsManager) // Functions defined by gnd.la/app.Template tmpl.RawFuncs(map[string]interface{}{ "t": nop, "tn": nop, "tc": nop, "tnc": nop, "reverse": nop, }) if err := tmpl.Parse(name); err != nil { return err } app.AddTemplatePlugin(&template.Plugin{Template: tmpl, Position: pos}) return nil }