templateManagerGin

package module
v0.0.0-...-5f9ee69 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 4 Imported by: 0

README

templateManager Gin Integration

This is the package for the templateManager renderer integration for the Gin framework.

For all options, please see the main repository.

Basic Usage

package main

import (
	"github.com/gin-gonic/gin"

	TM "github.com/paul-norman/go-template-manager-gin"
)

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

	engine := TM.Init("templates", ".html")
	engine.ExcludeDirectories([]string{"layouts", "partials"})
	if gin.IsDebugging() {
		engine.Reload(true)
		engine.Debug(true)
	}
	engine.Parse()

	router.HTMLRender = engine

	router.GET("/", func(c *gin.Context) {
		c.HTML(200, "home.html", gin.H{
			"Title": "Home",
		})
	})

	router.GET("/test", func(c *gin.Context) {
		c.HTML(200, "test.html", gin.H{
			"Title": "Test",
		})
	})

	router.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	*TM.TemplateManager
}

Struct wrapper allowing override of the Render function

func Init

func Init(directory string, extension string) *Engine

Creates a new Renderer instance

func (*Engine) Instance

func (e *Engine) Instance(name string, data any) render.Render

Renders a single template

type Params

type Params map[string]any

Convenience type allowing any variables types to be passed in

type Renderer

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

Struct wrapper replacing `render.HTML`

func (*Renderer) Render

func (r *Renderer) Render(w http.ResponseWriter) error

Called by Gin's contextual HTML function

func (*Renderer) WriteContentType

func (r *Renderer) WriteContentType(w http.ResponseWriter)

Required to fulfil Gin's Interface requirements

Jump to

Keyboard shortcuts

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