@@ -10,6 +10,7 @@ import (
1010 "crypto/sha256"
1111 "encoding/hex"
1212 "encoding/json"
13+ "fmt"
1314 "html"
1415 "html/template"
1516 "io"
@@ -182,6 +183,10 @@ func (ctx *Context) RedirectToFirst(location ...string) {
182183// HTML calls Context.HTML and converts template name to string.
183184func (ctx * Context ) HTML (status int , name base.TplName ) {
184185 log .Debug ("Template: %s" , name )
186+ var startTime = time .Now ()
187+ ctx .Data ["TmplLoadTimes" ] = func () string {
188+ return fmt .Sprint (time .Since (startTime ).Nanoseconds ()/ 1e6 ) + "ms"
189+ }
185190 if err := ctx .Render .HTML (ctx .Resp , status , string (name ), ctx .Data ); err != nil {
186191 ctx .ServerError ("Render failed" , err )
187192 }
@@ -190,6 +195,10 @@ func (ctx *Context) HTML(status int, name base.TplName) {
190195// HTMLString render content to a string but not http.ResponseWriter
191196func (ctx * Context ) HTMLString (name string , data interface {}) (string , error ) {
192197 var buf strings.Builder
198+ var startTime = time .Now ()
199+ ctx .Data ["TmplLoadTimes" ] = func () string {
200+ return fmt .Sprint (time .Since (startTime ).Nanoseconds ()/ 1e6 ) + "ms"
201+ }
193202 err := ctx .Render .HTML (& buf , 200 , string (name ), data )
194203 return buf .String (), err
195204}
@@ -547,10 +556,7 @@ func Contexter() func(next http.Handler) http.Handler {
547556 Data : map [string ]interface {}{
548557 "CurrentURL" : setting .AppSubURL + req .URL .RequestURI (),
549558 "PageStartTime" : startTime ,
550- "TmplLoadTimes" : func () string {
551- return time .Since (startTime ).String ()
552- },
553- "Link" : link ,
559+ "Link" : link ,
554560 },
555561 }
556562
0 commit comments