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: 5 months 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 (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-06T18:02:05.000Z (over 1 year ago)
- Last Synced: 2025-03-16T04:22:52.829Z (8 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 [](https://goreportcard.com/report/github.com/alexferl/echo-multitemplate) [](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 main
import (
	"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).