-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of concept: Template context function #24457
Conversation
Phew, I don't really know if I like the proposed approach. type Context {
…
loadUser func(ctx Context, <remaining params>)
}
func (ctx *Context) loadUser(<remaining params>) {
loadUser(ctx, <remaining params>)
} but that doesn't scale well and is a lot of overhead code to write… |
"import", no worry, the framework can handle them correctly later. |
I guess we can keep the same names, e.g. |
Should we merge this POC? |
Nope, it's far from complete. It needs #24461 and maybe some other PRs before merging. |
Partially for #24457 Major changes: 1. The old `signedUserNameStringPointerKey` is quite hacky, use `ctx.Data[SignedUser]` instead 2. Move duplicate code from `Contexter` to `CommonTemplateContextData` 3. Remove incorrect copying&pasting code `ctx.Data["Err_Password"] = true` in API handlers 4. Use one unique `RenderPanicErrorPage` for panic error page rendering 5. Move `stripSlashesMiddleware` to be the first middleware 6. Install global panic recovery handler, it works for both `install` and `web` 7. Make `500.tmpl` only depend minimal template functions/variables, avoid triggering new panics Screenshot: <details> ![image](https://user-images.githubusercontent.com/2114189/235444895-cecbabb8-e7dc-4360-a31c-b982d11946a7.png) </details>
Still blocked? |
Not blocked by code but blocked by my limited time 😭 |
Golang team make some progress text/template, html/template: add ExecuteFuncs https://go-review.googlesource.com/c/go/+/510738 I think the official "context function" support will be available soon. |
Wait for the Golang official solution |
cc @yardenshoham for #24342
This is a proof of concept of the "template context function".
Now in templates we only need to do:
TODO:
CtxFunc