From 4a469c8e1b3c1d153316aec9fd8cbdd3e1dd54e8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 5 Nov 2024 14:04:26 +0800 Subject: Refactor template ctx and render utils (#32422) Clean up the templates --- services/context/context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'services/context') diff --git a/services/context/context.go b/services/context/context.go index 42f7c3d9d1..6c7128ef68 100644 --- a/services/context/context.go +++ b/services/context/context.go @@ -100,6 +100,7 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext { tmplCtx := NewTemplateContext(ctx) tmplCtx["Locale"] = ctx.Base.Locale tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx) + tmplCtx["RenderUtils"] = templates.NewRenderUtils(ctx) tmplCtx["RootData"] = ctx.Data tmplCtx["Consts"] = map[string]any{ "RepoUnitTypeCode": unit.TypeCode, @@ -154,7 +155,9 @@ func Contexter() func(next http.Handler) http.Handler { ctx := NewWebContext(base, rnd, session.GetContextSession(req)) ctx.Data.MergeFrom(middleware.CommonTemplateContextData()) - ctx.Data["Context"] = ctx // TODO: use "ctx" in template and remove this + if setting.IsProd && !setting.IsInTesting { + ctx.Data["Context"] = ctx // TODO: use "ctx" in template and remove this + } ctx.Data["CurrentURL"] = setting.AppSubURL + req.URL.RequestURI() ctx.Data["Link"] = ctx.Link -- cgit v1.2.3