This commit is contained in:
Eden Kirin
2024-02-01 21:50:21 +01:00
parent 725e127881
commit 15ba332ae5
6 changed files with 102 additions and 25 deletions

View File

@ -3,7 +3,7 @@ package handlers
import (
"templ-tests/app/templates"
"github.com/gin-gonic/gin"
"github.com/gofiber/fiber/v2"
)
var pcAbout templates.PageContext = templates.PageContext{
@ -11,6 +11,7 @@ var pcAbout templates.PageContext = templates.PageContext{
ActivePage: "about",
}
func About(c *gin.Context) {
templates.About(pcAbout).Render(c, c.Writer)
func About(f *fiber.Ctx) error {
Render(f, templates.About(pcAbout))
return nil
}

View File

@ -4,10 +4,10 @@ import (
"templ-tests/app/templates"
"templ-tests/app/types"
"github.com/gin-gonic/gin"
"github.com/gofiber/fiber/v2"
)
func Home(c *gin.Context) {
func Home(f *fiber.Ctx) error {
user := types.User{
FirstName: "Pero",
LastName: "Perić",
@ -18,5 +18,6 @@ func Home(c *gin.Context) {
ActivePage: "home",
User: &user,
}
templates.Home(pc).Render(c, c.Writer)
Render(f, templates.Home(pc))
return nil
}

15
app/handlers/render.go Normal file
View File

@ -0,0 +1,15 @@
package handlers
import (
"github.com/a-h/templ"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/adaptor"
)
func Render(c *fiber.Ctx, component templ.Component, options ...func(*templ.ComponentHandler)) error {
componentHandler := templ.Handler(component)
for _, o := range options {
o(componentHandler)
}
return adaptor.HTTPHandler(componentHandler)(c)
}