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
Context pre-processors #18
Comments
Wrapper utils function for this data: e.GET("/page", func(c echo.Context) error {
return c.Render(http.StatusOK, "page.html", AuthData(c, echo.Map{"title": "Page file title!!"}))
})
func AuthData(c echo.Context, echo.Map) echo.Map{
user := c.Get("user")
//merge data with data
return xxxx
} |
@foolin That's my point I don't want to need to add it to Render on every single Handler, here it's what I did, wdyt ? // Template structure
type Template struct {
ev *echoview.ViewEngine
}
// Render template
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
// Add global methods if data is a map
if viewContext, isMap := data.(echo.Map); isMap {
viewContext["newVariable"] = "MyValue" // Here I can get the value from context
}
return t.ev.Render(w, name, data, c)
} |
Well, that's a good way. |
Thank you @foolin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I need to extract data from context and expose it to the template, mainly sure info so I can show that the user is logged in on the page header, do we have a way to do it ? do you think that maybe we can have the same functionality as
Config.Funcs
but they receive context? here it's my test middleware and the data I need available on all templates.And for echoview I think that this needs to go here, echoview.go
Let me know if that is a good approach, but I'm not sure how to fit this on other frameworks.
The text was updated successfully, but these errors were encountered: