pongo2echo

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: MIT Imports: 9 Imported by: 1

README

Pongo2Echo

Build GoDoc GitHub release (latest by date) Dependabot

pongo2echo provides pongo2 renderer for echo which is web application framework written by golang. Pongo2 is a template engine likes django-syntax for golang.

This package is useful when you use pongo2 template in echo.

Usage

Setup pongo2echo render when initialize echo.


import (
	"github.com/h3poteto/pongo2echo"
	"github.com/labstack/echo"
)

func main() {
	render := pongo2echo.NewRenderer()
	render.AddDirectory("server/templates")
	e := echo.New()
	e.Renderer = render

	e.GET("/", func(c echo.Context) error {
		// index.html.tpl is located in server/templates/index.html.tpl
		return c.Render(http.StatusOK, "index.html.tpl",  map[string]interface{}{"title": "Index"})
	})
	e.Logger.Fatal(e.Start(":1323"))
}

You can use pongo2 templte in Render function, and pass variables to template.

License

The package is available as open source under the terms of the MIT License.

Documentation

Overview

Package pongo2echo provides renderer for labstack's echo framework.

Usage:

import "github.com/h3poteto/pongo2echo"

You can set Pongo2Echo struct to echo.Renderer. For example:

render := pongo2echo.NewRenderer()
render.RegisterFilter("customFilter", customFilerFunc)
render.AddDirectory("server/templates")

e := echo.New()
e.Renderer = render

Then, you can use pongo2 in echo handler functions.

func Index(c echo.Context) error {
    // index.html.tpl is located in server/templates/index.html.tpl
    return c.Render(http.StatusOK, "index.html.tpl", map[string]interface{}{"title": "Index"})
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextProcessorFunc

type ContextProcessorFunc func(echoCtx echo.Context, pongoCtx pongo2.Context)

ContextProcessorFunc signature.

type Pongo2Echo

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

Pongo2Echo implements custom pongo2 rendering engine for echo.

func NewRenderer

func NewRenderer() *Pongo2Echo

NewRenderer creates a new Pongo2Echo struct.

func (*Pongo2Echo) Abs

func (p *Pongo2Echo) Abs(base, name string) string

Abs returns absolute path to file requested. Search path is configured in AddDirectory method. And default directory is "./templates".

func (*Pongo2Echo) AddDirectory

func (p *Pongo2Echo) AddDirectory(dir string)

AddDirectory adds a directory to the list of directories searched for templates. Default directory is "./templates".

func (*Pongo2Echo) Get

func (p *Pongo2Echo) Get(path string) (io.Reader, error)

Get reads the path's content from your local filesystem.

func (*Pongo2Echo) RegisterFilter

func (p *Pongo2Echo) RegisterFilter(name string, fn pongo2.FilterFunction)

RegisterFilter registers a custom filter. It calls pongo2.RegisterFilter method.

func (*Pongo2Echo) RegisterTag

func (p *Pongo2Echo) RegisterTag(name string, parserFunc pongo2.TagParser)

RegisterTag registers a custom tag. It calls pongo2.RegisterTag method.

func (*Pongo2Echo) Render

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

Render renders the view. Many other times, this is called in your echo handler functions.

func (*Pongo2Echo) SetDebug

func (p *Pongo2Echo) SetDebug(v bool)

SetDebug sets debug mode to the template set. See pongo2.TemplateSet.Debug for more information.

func (*Pongo2Echo) UseContextProcessor

func (p *Pongo2Echo) UseContextProcessor(processor ContextProcessorFunc)

UseContextProcessor adds context processor to the pipeline.

Jump to

Keyboard shortcuts

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