diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-08-08 09:22:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-08 01:22:47 +0000 |
commit | 69130532239ee7ade82977f456c12826e1adeb1e (patch) | |
tree | 81b8131bedc592af753481b7d222263b2c2655dc /routers/install | |
parent | 0c6ae61229bce9d9ad3d359cee927464968a2dd1 (diff) | |
download | gitea-69130532239ee7ade82977f456c12826e1adeb1e.tar.gz gitea-69130532239ee7ade82977f456c12826e1adeb1e.zip |
Start using template context function (#26254)
Before:
* `{{.locale.Tr ...}}`
* `{{$.locale.Tr ...}}`
* `{{$.root.locale.Tr ...}}`
* `{{template "sub" .}}`
* `{{template "sub" (dict "locale" $.locale)}}`
* `{{template "sub" (dict "root" $)}}`
* .....
With context function: only need to `{{ctx.Locale.Tr ...}}`
The "ctx" could be considered as a super-global variable for all
templates including sub-templates.
To avoid potential risks (any bug in the template context function
package), this PR only starts using "ctx" in "head.tmpl" and
"footer.tmpl" and it has a "DataRaceCheck". If there is anything wrong,
the code can be fixed or reverted easily.
Diffstat (limited to 'routers/install')
-rw-r--r-- | routers/install/install.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/routers/install/install.go b/routers/install/install.go index 6a8f561271..aa9c0f4986 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -68,9 +68,13 @@ func Contexter() func(next http.Handler) http.Handler { } defer baseCleanUp() + ctx.TemplateContext = context.NewTemplateContext(ctx) + ctx.TemplateContext["Locale"] = ctx.Locale + ctx.AppendContextValue(context.WebContextKey, ctx) ctx.Data.MergeFrom(middleware.CommonTemplateContextData()) ctx.Data.MergeFrom(middleware.ContextData{ + "Context": ctx, // TODO: use "ctx" in template and remove this "locale": ctx.Locale, "Title": ctx.Locale.Tr("install.install"), "PageIsInstall": true, |