Skip to content
Thanatat Tamtan edited this page Jun 9, 2026 · 5 revisions

Global is a map[any]any that 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",
})

To retrieve data via app using app.Global

fmt.Printf("%s: %s\n", app.Global("AppName"), app.Global("AppVersion"))

To 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>

Clone this wiki locally