README

echo-pongo2

Use pongo2 templates in the echo web framework

Usage

echo-pongo2 implements the echo Renderer interface

e := echo.New()
r, err := echo-pongo2.NewRenderer("./template")
e.SetRenderer(r)

somewhere in a handler

func Hello(c *echo.Context) error {
    data := map[string]string{"World":"mayowa"}
    return c.Render(http.StatusOK, "hello.html", data)
}

template: ./template/hello.html

Hello {{World}}

Options

opts := echo-pongo2.Options {
    Debug: False,
    Source: echo-pongo2.FromFile
}
r, err := echo-pongo2.NewRenderer("./template", opts)
  • Debug : When Debug is enabled Pongo2 wont cache parsed files
  • Source [FromFile|FromCache]: Determines if subsequent request for a previously rendered template is retrieved from cache or if the template is re-read from file Cache. Defaults to FromCache
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MixManifest

func MixManifest(publicFolder string) pongo2.FilterFunction

MixManifest reads a laravel-mix mix-manifest.json file and returns the hashed filename.

Types

type Options

type Options struct {
	Debug             bool
	Source            RenderSource
	MixManifestFolder string
}

Options to modify the renders behavior

type RenderSource

type RenderSource int

RenderSource source from which template will be rendered

const (
	// FromCache render template from cache
	FromCache RenderSource = iota
	// FromFile render template from file
	FromFile
)

type Renderer

type Renderer struct {
	BaseDir string
	TplSet  *pongo2.TemplateSet

	// contains filtered or unexported fields

}

Renderer manages a pongo2 TemplateSet

func NewRenderer

func NewRenderer(baseDir string, opts ...Options) (*Renderer, error)

NewRenderer creates a new instance of Renderer

func (*Renderer) RegisterFilter

func (r *Renderer) RegisterFilter(name string, fn pongo2.FilterFunction) error

RegisterFilter ...

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render implements echo.Render interface

func (*Renderer) SetGlobal

func (r *Renderer) SetGlobal(name string, val interface{})

SetGlobal ...