Skip to content

Commit

Permalink
chore: update echo example (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradydean authored May 12, 2024
1 parent 0d80290 commit 6a9dbff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/integration-echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ func main() {

// This custom Render replaces Echo's echo.Context.Render() with templ's templ.Component.Render().
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
ctx.Response().Writer.WriteHeader(statusCode)
return t.Render(ctx.Request().Context(), ctx.Response().Writer)
buf := templ.GetBuffer()
defer templ.ReleaseBuffer(buf)

if err := t.Render(ctx.Request().Context(), buf); err != nil {
return err
}

return ctx.HTML(statusCode, buf.String())
}

func HomeHandler(c echo.Context) error {
Expand Down

0 comments on commit 6a9dbff

Please sign in to comment.