-
Notifications
You must be signed in to change notification settings - Fork 2
Global
Thanatat Tamtan edited this page Sep 23, 2023
·
4 revisions
Global is a map[any]any acts like app's constant storage.
Data can be added to global via app.Globals
app := hime.New()
app.Globals(hime.Globals{
"AppName": "HimeExample",
"AppVersion": "1.0.0",
})For retrieve data via app using app.Global
fmt.Printf("%s: %s\n", app.Global("AppName"), app.Global("AppVersion"))For retrieve data via context using ctx.Global
func version(ctx *hime.Context) error {
return ctx.String("%s: %s", ctx.Global("AppName"), ctx.Global("AppVersion"))
}Hime will inject template func to retrieve global data inside template
<h1>{{global "AppName"}}: {{global "AppVersion"}}</h1>