ginhtml

package
v0.0.0-...-adffa0d Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

ginhtml

support for gin html template

Install

go get -u github.com/pandafw/ginx
Example
package main

import (
	"net/http"
	"github.com/gin-gonic/gin"
	"github.com/pandafw/pango/ginx/ginhtml"
)

func main() {
	// new template engine
	ghe := ginhtml.NewEngine()
	if err = ghe.Load("templates"); err != nil {
		panic(err)
	}

	router := gin.Default()

	// customize gin html render
	router.HTMLRender = ghe

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

	router.Run(":9090")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	*tpl.HTMLTemplate
}

Engine html engine for gin

func NewEngine

func NewEngine() *Engine

NewEngine create a html engine for gin

func (*Engine) Instance

func (ghe *Engine) Instance(name string, data interface{}) render.Render

Instance implement gin interface

type Render

type Render struct {
	// contains filtered or unexported fields
}

Render view render implement gin interface

func (Render) Render

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

Render writes data with custom ContentType.

func (Render) WriteContentType

func (v Render) 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