-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Go Fiber Support / Example? #349
Comments
I think that since the Fiber context type implements io.Writer, it should be a case of: app.Get("/", func(c *fiber.Ctx) error {
return templConponent("hello").Render(c.Context(), c)
}) But I'm just typing this on a mobile, haven't had chance to try it! |
I created a helper that does this: func Render(c *fiber.Ctx, component templ.Component, options ...func(*templ.ComponentHandler)) error {
componentHandler := templ.Handler(layout.Main(component))
for _, o := range options {
o(componentHandler)
}
return adaptor.HTTPHandler(componentHandler)(c)
} This way you can use your render-function like this, which I found easiest: app.Get("/", func(c *fiber.Ctx) error {
return view.Render(c, MyTemplView())
}) /e: func ErrorHandler(c *fiber.Ctx, err error) error {
return view.Render(c, pages.ErrorView(err.Error()), templ.WithStatus(http.StatusNotFound))
} Which results in sending the correct status codes. |
I think we can consider this closed. We've got a good example now, thanks to @bastianwegge. |
Corresponding ticket on Go Fiber's side: gofiber/template#302
Based on some of the conversation going on over there, it looks like there are a few different approaches to integrating both Templ and Fiber. Since there are already examples of Gin and Chi, maybe one could be added for Fiber?
The text was updated successfully, but these errors were encountered: