Global is a map[any]any that acts like app's constant storage.
map[any]any
Data can be added to global via app.Globals
app.Globals
app := hime.New() app.Globals(hime.Globals{ "AppName": "HimeExample", "AppVersion": "1.0.0", })
To retrieve data via app using app.Global
app.Global
fmt.Printf("%s: %s\n", app.Global("AppName"), app.Global("AppVersion"))
To retrieve data via context using ctx.Global
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>
There was an error while loading. Please reload this page.