package
0.3.0
Repository: https://github.com/foolin/goview.git
Documentation: pkg.go.dev

# README

GinView

GoDoc Widget

goview support for gin template

Install


go get -u github.com/foolin/goview

go get -u github.com/foolin/goview/supports/ginview

Example


package main

import (
	"github.com/foolin/goview/supports/ginview"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	router := gin.Default()

	//new template engine
	router.HTMLRender = ginview.Default()

	router.GET("/", func(ctx *gin.Context) {
		//render with master
		ctx.HTML(http.StatusOK, "index", gin.H{
			"title": "Index title!",
			"add": func(a int, b int) int {
				return a + b
			},
		})
	})

	router.GET("/page", func(ctx *gin.Context) {
		//render only file, must full name with extension
		ctx.HTML(http.StatusOK, "page.html", gin.H{"title": "Page file title!!"})
	})

	router.Run(":9090")
}

Project structure:

|-- app/views/
    |--- index.html          
    |--- page.html
    |-- layouts/
        |--- footer.html
        |--- master.html
    

See in "examples/basic" folder

Gin example

More examples

See _examples/ for a variety of examples.

# Functions

Default new default engine.
HTML html render for template You should use helper func `Middleware()` to set the supplied TemplateEngine and make `HTML()` work validly.
Middleware gin middleware wrapper.
New new view engine for gin.
NewMiddleware gin middleware for func `gintemplate.HTML()`.
Wrap wrap view engine for goview.ViewEngine.

# Structs

ViewEngine view engine for gin.
ViewRender view render implement gin interface.