{"id":13413847,"url":"https://github.com/foolin/goview","last_synced_at":"2025-05-15T19:09:06.594Z","repository":{"id":44840238,"uuid":"181298296","full_name":"foolin/goview","owner":"foolin","description":"Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.","archived":false,"fork":false,"pushed_at":"2023-10-29T03:57:41.000Z","size":10761,"stargazers_count":434,"open_issues_count":15,"forks_count":37,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T01:36:20.246Z","etag":null,"topics":["chi","echo","framework","gin","go","golang","gorice","html","library","template","view"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foolin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"supports/echoview-v4/README.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-14T11:22:41.000Z","updated_at":"2025-03-23T08:47:46.000Z","dependencies_parsed_at":"2022-09-26T20:01:25.226Z","dependency_job_id":"9e510bf7-a1f9-457e-bace-8d07df370564","html_url":"https://github.com/foolin/goview","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolin%2Fgoview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolin%2Fgoview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolin%2Fgoview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foolin%2Fgoview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foolin","download_url":"https://codeload.github.com/foolin/goview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254404357,"owners_count":22065641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chi","echo","framework","gin","go","golang","gorice","html","library","template","view"],"created_at":"2024-07-30T20:01:51.074Z","updated_at":"2025-05-15T19:09:06.569Z","avatar_url":"https://github.com/foolin.png","language":"Go","readme":"# goview\n\n[![GoDoc Widget]][GoDoc] [![Travis Widget]][Travis] [![GoReportCard Widget]][GoReportCard] \n\nGoview is a lightweight, minimalist and idiomatic template library based on golang [html/template](https://golang.org/pkg/html/template/) for building Go web application.\n\n## Contents\n\n- [Install](#install)\n- [Features](#features)\n- [Docs](#docs)\n- [Supports](#supports)\n    - [Gin Framework](https://github.com/foolin/goview/tree/master/supports/ginview)\n    - [Iris Framework](https://github.com/foolin/goview/tree/master/supports/irisview)\n    - [Echo Framework](https://github.com/foolin/goview/tree/master/supports/echoview)\n    - [Go.Rice](https://github.com/foolin/goview/tree/master/supports/gorice)\n- [Usage](#usage)\n    - [Overview](#overview)\n    - [Config](#config)\n    - [Include syntax](#include-syntax)\n    - [Render name](#render-name)\n\t- [Custom template functions](#custom-template-functions)\n- [Examples](#examples)\n    - [Basic example](#basic-example)\n    - [Gin example](#gin-example)\n    - [Iris example](#iris-example)\n    - [Iris multiple example](#iris-multiple-example)\n    - [Echo example](#echo-example)\n    - [Go-chi example](#go-chi-example)\n    - [Advance example](#advance-example)\n    - [Multiple example](#multiple-example)\n    - [go.rice example](#gorice-example)\n    - [more examples](#more-examples)\n\n\n## Install\n```bash\ngo get github.com/foolin/goview\n```\n\n\n## Features\n\n* **Lightweight** - use golang html/template syntax.\n* **Easy** - easy use for your web application.\n* **Fast** - Support configure cache template.\n* **Include syntax** - Support include file.\n* **Master layout** - Support configure master layout file.\n* **Extension** - Support configure template file extension.\n* **Easy** - Support configure templates directory.\n* **Auto reload** - Support dynamic reload template(disable cache mode).\n* **Multiple Engine** - Support multiple templates for frontend and backend.\n* **No external dependencies** - plain ol' Go html/template.\n* **Gorice** - Support gorice for package resources.\n* **Gin/Iris/Echo/Chi** - Support gin framework, Iris framework, echo framework, go-chi framework.\n\n\n## Docs\nSee \u003chttps://www.godoc.org/github.com/foolin/goview\u003e\n\n\n## Supports\n- **[ginview](https://github.com/foolin/goview/tree/master/supports/ginview)** goview for gin framework\n- **[irisview](https://github.com/foolin/goview/tree/master/supports/irisview)** goview for Iris framework\n- **[echoview](https://github.com/foolin/goview/tree/master/supports/echoview)** goview for echo framework\n- **[gorice](https://github.com/foolin/goview/tree/master/supports/gorice)** goview for go.rice\n\n\n## Usage\n\n### Overview\n\nProject structure:\n\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n   \n```\n\nUse default instance:\n\n```go\n    //write http.ResponseWriter\n    //\"index\" -\u003e index.html\n    goview.Render(writer, http.StatusOK, \"index\", goview.M{})\n```\n\nUse new instance with config:\n\n```go\n\n    gv := goview.New(goview.Config{\n        Root:      \"views\",\n        Extension: \".tpl\",\n        Master:    \"layouts/master\",\n        Partials:  []string{\"partials/ad\"},\n        Funcs: template.FuncMap{\n            \"sub\": func(a, b int) int {\n                return a - b\n            },\n            \"copy\": func() string {\n                return time.Now().Format(\"2006\")\n            },\n        },\n        DisableCache: true,\n\tDelims:    Delims{Left: \"{{\", Right: \"}}\"},\n    })\n    \n    //Set new instance\n    goview.Use(gv)\n    \n    //write http.ResponseWriter\n    goview.Render(writer, http.StatusOK, \"index\", goview.M{})\n\n```\n\n\nUse multiple instance with config:\n\n```go\n    //============== Frontend ============== //\n    gvFrontend := goview.New(goview.Config{\n        Root:      \"views/frontend\",\n        Extension: \".tpl\",\n        Master:    \"layouts/master\",\n        Partials:  []string{\"partials/ad\"},\n        Funcs: template.FuncMap{\n            \"sub\": func(a, b int) int {\n                return a - b\n            },\n            \"copy\": func() string {\n                return time.Now().Format(\"2006\")\n            },\n        },\n        DisableCache: true,\n\tDelims:       Delims{Left: \"{{\", Right: \"}}\"},\n    })\n    \n    //write http.ResponseWriter\n    gvFrontend.Render(writer, http.StatusOK, \"index\", goview.M{})\n    \n    //============== Backend ============== //\n    gvBackend := goview.New(goview.Config{\n        Root:      \"views/backend\",\n        Extension: \".tpl\",\n        Master:    \"layouts/master\",\n        Partials:  []string{\"partials/ad\"},\n        Funcs: template.FuncMap{\n            \"sub\": func(a, b int) int {\n                return a - b\n            },\n            \"copy\": func() string {\n                return time.Now().Format(\"2006\")\n            },\n        },\n        DisableCache: true,\n\tDelims:       Delims{Left: \"{{\", Right: \"}}\"},\n    })\n    \n    //write http.ResponseWriter\n    gvBackend.Render(writer, http.StatusOK, \"index\", goview.M{})\n\n```\n\n### Config\n\n```go\ngoview.Config{\n    Root:      \"views\", //template root path\n    Extension: \".tpl\", //file extension\n    Master:    \"layouts/master\", //master layout file\n    Partials:  []string{\"partials/head\"}, //partial files\n    Funcs: template.FuncMap{\n        \"sub\": func(a, b int) int {\n            return a - b\n        },\n        // more funcs\n    },\n    DisableCache: false, //if disable cache, auto reload template file for debug.\n    Delims:       Delims{Left: \"{{\", Right: \"}}\"},\n}\n```\n\n### Include syntax\n\n```go\n//template file\n{{include \"layouts/footer\"}}\n```\n\n### Render name: \n\nRender name use `index` without `.html` extension, that will render with master layout.\n\n- **\"index\"** - Render with master layout.\n- **\"index.html\"** - Not render with master layout.\n\n```\nNotice: `.html` is default template extension, you can change with config\n```\n\n\nRender with master\n\n```go\n//use name without extension `.html`\ngoview.Render(w, http.StatusOK, \"index\", goview.M{})\n```\n\nThe `w` is instance of  `http.ResponseWriter`\n\nRender only file(not use master layout)\n```go\n//use full name with extension `.html`\ngoview.Render(w, http.StatusOK, \"page.html\", goview.M{})\n```\n\n### Custom template functions\n\nWe have two type of functions `global functions`, and `temporary functions`.\n\n`Global functions` are set within the `config`.\n\n```go\ngoview.Config{\n\tFuncs: template.FuncMap{\n\t\t\"reverse\": e.Reverse,\n\t},\n}\n```\n\n```go\n//template file\n{{ reverse \"route-name\" }}\n```\n\n`Temporary functions` are set inside the handler.\n\n```go\nhttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\terr := goview.Render(w, http.StatusOK, \"index\", goview.M{\n\t\t\"reverse\": e.Reverse,\n\t})\n\tif err != nil {\n\t\tfmt.Fprintf(w, \"Render index error: %v!\", err)\n\t}\n})\n```\n```go\n//template file\n{{ call $.reverse \"route-name\" }}\n```\n\n\n\n## Examples\n\nSee [_examples/](https://github.com/foolin/goview/blob/master/_examples/) for a variety of examples.\n\n\n### Basic example\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/foolin/goview\"\n\t\"net/http\"\n)\n\nfunc main() {\n\n\t//render index use `index` without `.html` extension, that will render with master layout.\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"index\", goview.M{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render index error: %v!\", err)\n\t\t}\n\n\t})\n\n\t//render page use `page.tpl` with '.html' will only file template without master layout.\n\thttp.HandleFunc(\"/page\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"page.html\", goview.M{\"title\": \"Page file title!!\"})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render page.html error: %v!\", err)\n\t\t}\n\t})\n\n\tfmt.Println(\"Listening and serving HTTP on :9090\")\n\thttp.ListenAndServe(\":9090\", nil)\n\n}\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n    \n\nSee in \"examples/basic\" folder\n```\n\n[Basic example](https://github.com/foolin/goview/tree/master/_examples/basic)\n\n\n### Gin example\n\n```bash\ngo get github.com/foolin/goview/supports/ginview\n```\n\n```go\n\npackage main\n\nimport (\n\t\"github.com/foolin/goview/supports/ginview\"\n\t\"github.com/gin-gonic/gin\"\n\t\"net/http\"\n)\n\nfunc main() {\n\trouter := gin.Default()\n\n\t//new template engine\n\trouter.HTMLRender = ginview.Default()\n\n\trouter.GET(\"/\", func(ctx *gin.Context) {\n\t\t//render with master\n\t\tctx.HTML(http.StatusOK, \"index\", gin.H{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t})\n\n\trouter.GET(\"/page\", func(ctx *gin.Context) {\n\t\t//render only file, must full name with extension\n\t\tctx.HTML(http.StatusOK, \"page.html\", gin.H{\"title\": \"Page file title!!\"})\n\t})\n\n\trouter.Run(\":9090\")\n}\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n    \n\nSee in \"examples/basic\" folder\n```\n\n[Gin example](https://github.com/foolin/goview/tree/master/_examples/gin)\n\n### Iris example\n\n```bash\n$ go get github.com/foolin/goview/supports/irisview\n```\n\n```go\npackage main\n\nimport (\n\t\"github.com/foolin/goview/supports/irisview\"\n\t\"github.com/kataras/iris/v12\"\n)\n\nfunc main() {\n\tapp := iris.New()\n\n\t// Register the goview template engine.\n\tapp.RegisterView(irisview.Default())\n\n\tapp.Get(\"/\", func(ctx iris.Context) {\n\t\t// Render with master.\n\t\tctx.View(\"index\", iris.Map{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t})\n\n\tapp.Get(\"/page\", func(ctx iris.Context) {\n\t\t// Render only file, must full name with extension.\n\t\tctx.View(\"page.html\", iris.Map{\"title\": \"Page file title!!\"})\n\t})\n\n\tapp.Listen(\":9090\")\n}\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n    \n\nSee in \"examples/iris\" folder\n```\n\n[Iris example](https://github.com/foolin/goview/tree/master/_examples/iris)\n\n\n### Iris multiple example\n\n```go\npackage main\n\nimport (\n\t\"html/template\"\n\t\"time\"\n\n\t\"github.com/foolin/goview\"\n\t\"github.com/foolin/goview/supports/irisview\"\n\t\"github.com/kataras/iris/v12\"\n)\n\nfunc main() {\n\tapp := iris.New()\n\n\t// Register a new template engine.\n\tapp.RegisterView(irisview.New(goview.Config{\n\t\tRoot:      \"views/frontend\",\n\t\tExtension: \".html\",\n\t\tMaster:    \"layouts/master\",\n\t\tPartials:  []string{\"partials/ad\"},\n\t\tFuncs: template.FuncMap{\n\t\t\t\"copy\": func() string {\n\t\t\t\treturn time.Now().Format(\"2006\")\n\t\t\t},\n\t\t},\n\t\tDisableCache: true,\n\t}))\n\n\tapp.Get(\"/\", func(ctx iris.Context) {\n\t\tctx.View(\"index\", iris.Map{\n\t\t\t\"title\": \"Frontend title!\",\n\t\t})\n\t})\n\n\t//=========== Backend ===========//\n\n\t// Assign a new template middleware.\n\tmw := irisview.NewMiddleware(goview.Config{\n\t\tRoot:      \"views/backend\",\n\t\tExtension: \".html\",\n\t\tMaster:    \"layouts/master\",\n\t\tPartials:  []string{},\n\t\tFuncs: template.FuncMap{\n\t\t\t\"copy\": func() string {\n\t\t\t\treturn time.Now().Format(\"2006\")\n\t\t\t},\n\t\t},\n\t\tDisableCache: true,\n\t})\n\n\tbackendGroup := app.Party(\"/admin\", mw)\n\n\tbackendGroup.Get(\"/\", func(ctx iris.Context) {\n\t\t// Use the ctx.View as you used to. Zero changes to your codebase,\n\t\t// even if you use multiple templates.\n\t\tctx.View(\"index\", iris.Map{\n\t\t\t\"title\": \"Backend title!\",\n\t\t})\n\t})\n\n\tapp.Listen(\":9090\")\n}\n```\n\nProject structure:\n```go\n|-- app/views/\n    |-- fontend/\n        |--- index.html\n        |-- layouts/\n            |--- footer.html\n            |--- head.html\n            |--- master.html\n        |-- partials/\n     \t   |--- ad.html\n    |-- backend/\n        |--- index.html\n        |-- layouts/\n            |--- footer.html\n            |--- head.html\n            |--- master.html\n        \nSee in \"examples/iris-multiple\" folder\n```\n\n[Iris multiple example](https://github.com/foolin/goview/tree/master/_examples/iris-multiple)\n\n### Echo example\n\nEcho \u003c=v3 version:\n```bash\ngo get github.com/foolin/goview/supports/echoview\n```\n\nEcho v4 version:\n\n```bash\ngo get github.com/foolin/goview/supports/echoview-v4\n```\n\n\n```go\n\npackage main\n\nimport (\n\t\"github.com/foolin/goview/supports/echoview\"\n\t\"github.com/labstack/echo\"\n\t\"github.com/labstack/echo/middleware\"\n\t\"net/http\"\n)\n\nfunc main() {\n\n\t// Echo instance\n\te := echo.New()\n\n\t// Middleware\n\te.Use(middleware.Logger())\n\te.Use(middleware.Recover())\n\n\t//Set Renderer\n\te.Renderer = echoview.Default()\n\n\t// Routes\n\te.GET(\"/\", func(c echo.Context) error {\n\t\t//render with master\n\t\treturn c.Render(http.StatusOK, \"index\", echo.Map{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t})\n\n\te.GET(\"/page\", func(c echo.Context) error {\n\t\t//render only file, must full name with extension\n\t\treturn c.Render(http.StatusOK, \"page.html\", echo.Map{\"title\": \"Page file title!!\"})\n\t})\n\n\t// Start server\n\te.Logger.Fatal(e.Start(\":9090\"))\n}\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n    \n\nSee in \"examples/basic\" folder\n```\n\n[Echo example](https://github.com/foolin/goview/tree/master/_examples/echo)\n[Echo v4 example](https://github.com/foolin/goview/tree/master/_examples/echo-v4)\n\n\n### Go-chi example\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/foolin/goview\"\n\t\"github.com/go-chi/chi\"\n\t\"net/http\"\n)\n\nfunc main() {\n\n\tr := chi.NewRouter()\n\n\t//render index use `index` without `.html` extension, that will render with master layout.\n\tr.Get(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"index\", goview.M{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render index error: %v!\", err)\n\t\t}\n\t})\n\n\t//render page use `page.tpl` with '.html' will only file template without master layout.\n\tr.Get(\"/page\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"page.html\", goview.M{\"title\": \"Page file title!!\"})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render page.html error: %v!\", err)\n\t\t}\n\t})\n\n\tfmt.Println(\"Listening and serving HTTP on :9090\")\n\thttp.ListenAndServe(\":9090\", r)\n\n}\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n    \n\nSee in \"examples/basic\" folder\n```\n\n[Chi example](https://github.com/foolin/goview/tree/master/_examples/go-chi)\n\n\n\n### Advance example\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/foolin/goview\"\n\t\"html/template\"\n\t\"net/http\"\n\t\"time\"\n)\n\nfunc main() {\n\n\tgv := goview.New(goview.Config{\n\t\tRoot:      \"views\",\n\t\tExtension: \".tpl\",\n\t\tMaster:    \"layouts/master\",\n\t\tPartials:  []string{\"partials/ad\"},\n\t\tFuncs: template.FuncMap{\n\t\t\t\"sub\": func(a, b int) int {\n\t\t\t\treturn a - b\n\t\t\t},\n\t\t\t\"copy\": func() string {\n\t\t\t\treturn time.Now().Format(\"2006\")\n\t\t\t},\n\t\t},\n\t\tDisableCache: true,\n\t})\n\n\t//Set new instance\n\tgoview.Use(gv)\n\n\t//render index use `index` without `.html` extension, that will render with master layout.\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"index\", goview.M{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render index error: %v!\", err)\n\t\t}\n\n\t})\n\n\t//render page use `page.tpl` with '.html' will only file template without master layout.\n\thttp.HandleFunc(\"/page\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"page.tpl\", goview.M{\"title\": \"Page file title!!\"})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render page.html error: %v!\", err)\n\t\t}\n\t})\n\n\tfmt.Println(\"Listening and serving HTTP on :9090\")\n\thttp.ListenAndServe(\":9090\", nil)\n}\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.tpl          \n    |--- page.tpl\n    |-- layouts/\n        |--- footer.tpl\n        |--- head.tpl\n        |--- master.tpl\n    |-- partials/\n        |--- ad.tpl\n    \n\nSee in \"examples/advance\" folder\n```\n\n[Advance example](https://github.com/foolin/goview/tree/master/_examples/advance)\n\n### Multiple example\n```go\n\npackage main\n\nimport (\n\t\"html/template\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/foolin/goview\"\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n\trouter := gin.Default()\n\n\t//new template engine\n\trouter.HTMLRender = gintemplate.New(gintemplate.TemplateConfig{\n\t\tRoot:      \"views/fontend\",\n\t\tExtension: \".html\",\n\t\tMaster:    \"layouts/master\",\n\t\tPartials:  []string{\"partials/ad\"},\n\t\tFuncs: template.FuncMap{\n\t\t\t\"copy\": func() string {\n\t\t\t\treturn time.Now().Format(\"2006\")\n\t\t\t},\n\t\t},\n\t\tDisableCache: true,\n\t})\n\n\trouter.GET(\"/\", func(ctx *gin.Context) {\n\t\t// `HTML()` is a helper func to deal with multiple TemplateEngine's.\n\t\t// It detects the suitable TemplateEngine for each path automatically.\n\t\tgintemplate.HTML(ctx, http.StatusOK, \"index\", gin.H{\n\t\t\t\"title\": \"Fontend title!\",\n\t\t})\n\t})\n\n\t//=========== Backend ===========//\n\n\t//new middleware\n\tmw := gintemplate.NewMiddleware(gintemplate.TemplateConfig{\n\t\tRoot:      \"views/backend\",\n\t\tExtension: \".html\",\n\t\tMaster:    \"layouts/master\",\n\t\tPartials:  []string{},\n\t\tFuncs: template.FuncMap{\n\t\t\t\"copy\": func() string {\n\t\t\t\treturn time.Now().Format(\"2006\")\n\t\t\t},\n\t\t},\n\t\tDisableCache: true,\n\t})\n\n\t// You should use helper func `Middleware()` to set the supplied\n\t// TemplateEngine and make `HTML()` work validly.\n\tbackendGroup := router.Group(\"/admin\", mw)\n\n\tbackendGroup.GET(\"/\", func(ctx *gin.Context) {\n\t\t// With the middleware, `HTML()` can detect the valid TemplateEngine.\n\t\tgintemplate.HTML(ctx, http.StatusOK, \"index\", gin.H{\n\t\t\t\"title\": \"Backend title!\",\n\t\t})\n\t})\n\n\trouter.Run(\":9090\")\n}\n\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |-- fontend/\n        |--- index.html\n        |-- layouts/\n            |--- footer.html\n            |--- head.html\n            |--- master.html\n        |-- partials/\n     \t   |--- ad.html\n    |-- backend/\n        |--- index.html\n        |-- layouts/\n            |--- footer.html\n            |--- head.html\n            |--- master.html\n        \nSee in \"examples/multiple\" folder\n```\n\n[Multiple example](https://github.com/foolin/goview/tree/master/_examples/multiple)\n\n\n### go.rice example\n\n```bash\ngo get github.com/foolin/goview/supports/gorice\n```\n\n```go\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/GeertJohan/go.rice\"\n\t\"github.com/foolin/goview\"\n\t\"github.com/foolin/goview/supports/gorice\"\n\t\"net/http\"\n)\n\nfunc main() {\n\n\t//static\n\tstaticBox := rice.MustFindBox(\"static\")\n\tstaticFileServer := http.StripPrefix(\"/static/\", http.FileServer(staticBox.HTTPBox()))\n\thttp.Handle(\"/static/\", staticFileServer)\n\n\t//new view engine\n\tgv := gorice.New(rice.MustFindBox(\"views\"))\n\t//set engine for default instance\n\tgoview.Use(gv)\n\n\t//render index use `index` without `.html` extension, that will render with master layout.\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"index\", goview.M{\n\t\t\t\"title\": \"Index title!\",\n\t\t\t\"add\": func(a int, b int) int {\n\t\t\t\treturn a + b\n\t\t\t},\n\t\t})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render index error: %v!\", err)\n\t\t}\n\n\t})\n\n\t//render page use `page.tpl` with '.html' will only file template without master layout.\n\thttp.HandleFunc(\"/page\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := goview.Render(w, http.StatusOK, \"page.html\", goview.M{\"title\": \"Page file title!!\"})\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(w, \"Render page.html error: %v!\", err)\n\t\t}\n\t})\n\n\tfmt.Println(\"Listening and serving HTTP on :9090\")\n\thttp.ListenAndServe(\":9090\", nil)\n}\n\n```\n\nProject structure:\n```go\n|-- app/views/\n    |--- index.html          \n    |--- page.html\n    |-- layouts/\n        |--- footer.html\n        |--- master.html\n|-- app/static/  \n    |-- css/\n        |--- bootstrap.css   \t\n    |-- img/\n        |--- gopher.png\n\nSee in \"examples/gorice\" folder\n```\n\n[gorice example](https://github.com/foolin/goview/tree/master/_examples/gorice)\n\n### More examples\n\nSee [_examples/](https://github.com/foolin/goview/blob/master/_examples/) for a variety of examples.\n\n\n[GoDoc]: https://godoc.org/github.com/foolin/goview\n[GoDoc Widget]: https://godoc.org/github.com/foolin/goview?status.svg\n[Travis]: https://travis-ci.org/foolin/goview\n[Travis Widget]: https://travis-ci.org/foolin/goview.svg?branch=master\n[GoReportCard]: https://goreportcard.com/report/github.com/foolin/goview\n[GoReportCard Widget]: https://goreportcard.com/badge/github.com/foolin/goview\n[GoCover]: https://goreportcard.com/report/github.com/foolin/goview\n[GoCover Widget]: https://goreportcard.com/badge/github.com/foolin/goview\n\n\n### Todo\n [ ] Add Partials support directory or glob\n [ ] Add functions support.\n \n","funding_links":[],"categories":["Template Engines","Go","HTML template engines","HTML Templates","模板引擎","模板引擎`模版渲染和模版生成处理库`","Relational Databases"],"sub_categories":["HTTP Clients","查询语","交互工具","HTTP客户端"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoolin%2Fgoview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoolin%2Fgoview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoolin%2Fgoview/lists"}