Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexferl/echo-multitemplate
Custom HTML renderer to support multiple templates in Echo framework
https://github.com/alexferl/echo-multitemplate
echo echo-framework echo-multitemplate go golang golang-template labstack-echo multitemplate
Last synced: about 1 month ago
JSON representation
Custom HTML renderer to support multiple templates in Echo framework
- Host: GitHub
- URL: https://github.com/alexferl/echo-multitemplate
- Owner: alexferl
- Created: 2024-01-22T18:34:47.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-02-06T18:02:05.000Z (9 months ago)
- Last Synced: 2024-06-21T18:46:14.972Z (5 months ago)
- Topics: echo, echo-framework, echo-multitemplate, go, golang, golang-template, labstack-echo, multitemplate
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# echo-multitemplate [![Go Report Card](https://goreportcard.com/badge/github.com/alexferl/echo-multitemplate)](https://goreportcard.com/report/github.com/alexferl/echo-multitemplate) [![codecov](https://codecov.io/gh/alexferl/echo-multitemplate/branch/master/graph/badge.svg)](https://codecov.io/gh/alexferl/echo-multitemplate)
This is a custom HTML renderer to support multiple templates, ie. more than one `*template.Template` for the
[Echo](https://github.com/labstack/echo) framework## Installing
```shell
go get github.com/alexferl/echo-multitemplate
```### Code example
See [examples/simple/example.go](examples/simple/example.go)```go
package mainimport (
"net/http""github.com/alexferl/echo-multitemplate"
"github.com/labstack/echo/v4"
)func createMyRender() multitemplate.Renderer {
r := multitemplate.New()
r.AddFromFiles("index", "templates/base.html", "templates/index.html")
r.AddFromFiles("article", "templates/base.html", "templates/index.html", "templates/article.html")
return r
}func main() {
e := echo.New()
e.Renderer = createMyRender()
e.GET("/", func(c echo.Context) error {
return c.Render(http.StatusOK, "index", echo.Map{"title": "Index"})
})e.GET("/article", func(c echo.Context) error {
return c.Render(http.StatusOK, "article", echo.Map{"title": "Article"})
})e.Logger.Fatal(e.Start("localhost:1323"))
}
```## Credits
Port of [gin-contrib/multitemplate](https://github.com/gin-contrib/multitemplate).