Replies: 1 comment 3 replies
-
You need to implement This is extremely basic example that does not choose template or pass data AND compiles template for EACH request import (
"errors"
"github.com/Joker/jade"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"html/template"
"io"
"log"
"net/http"
)
type pugRenderer struct {
}
func (r pugRenderer) Render(w io.Writer, _ string, _ interface{}, _ echo.Context) error {
jadeTpl, _ := jade.Parse("jade", []byte("doctype 5\n html: body: p Hello #{.Word} !"))
goTpl, _ := template.New("html").Parse(jadeTpl)
return goTpl.Execute(w, struct{ Word string }{"jade"})
}
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Renderer = pugRenderer{}
e.GET("/", func(c echo.Context) error {
return c.Render(http.StatusOK, "NotUsed", "NotUsed")
})
if err := e.Start(":8080"); !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
} NB: this example does not use go generated files. I took the from https://github.com/Joker/jade block
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! I'm a little newbie in Go, I come from Node.js. I want to use Pug as template engine. I picked this implementation module, but while it looks fully compatible with Fiber framework, I don't know how to implement it in Echo framework. I looked this article about template rendering, but I'm getting a little confused:
Beta Was this translation helpful? Give feedback.
All reactions