Basics
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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
15
app/handlers/render.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user