ginview

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 4 Imported by: 0

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTML

func HTML(ctx *gin.Context, code int, name string, data interface{})

HTML html render for template You should use helper func `Middleware()` to set the supplied TemplateEngine and make `HTML()` work validly.

func Middleware

func Middleware(e *ViewEngine) gin.HandlerFunc

Middleware gin middleware wrapper

func NewMiddleware

func NewMiddleware(config goview.Config) gin.HandlerFunc

NewMiddleware gin middleware for func `gintemplate.HTML()`

Types

type ViewEngine

type ViewEngine struct {
	*goview.ViewEngine
}

ViewEngine view engine for gin

func Default

func Default() *ViewEngine

Default new default engine

func New

func New(config goview.Config) *ViewEngine

New new view engine for gin

func Wrap

func Wrap(engine *goview.ViewEngine) *ViewEngine

Wrap wrap view engine for goview.ViewEngine

func (*ViewEngine) HTML

func (e *ViewEngine) HTML(ctx *gin.Context, code int, name string, data interface{})

HTML render html

func (*ViewEngine) Instance

func (e *ViewEngine) Instance(name string, data interface{}) render.Render

Instance implement gin interface

type ViewRender

type ViewRender struct {
	Engine *ViewEngine
	Name   string
	Data   interface{}
}

ViewRender view render implement gin interface

func (ViewRender) Render

func (v ViewRender) Render(w http.ResponseWriter) error

Render (YAML) marshals the given interface object and writes data with custom ContentType.

func (ViewRender) WriteContentType

func (v ViewRender) WriteContentType(w http.ResponseWriter)

WriteContentType write html content type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL