README

template

Use pongo2 templates in the echo web framework

Usage

pongo2 implements the echo Renderer interface

e := echo.New()
t, err := template.NewRenderer("./template")
if err != nil {
    panic(err)
}
e.Renderer = t

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}}

配合 webpack 使用

{{"app" | encore_link_tags | safe}}
<!-- 
    <link href="./public/build/app.css">
 -->
{{"app" | encore_script_tags | safe}}
<!-- 
    <script src="./public/build/runtime.js"></script>
    <script src="./public/build/app.js"></script>
 -->
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	BaseDir string
	TplSet  *pongo2.TemplateSet
}

    Renderer manages a pongo2 TemplateSet

    func NewRenderer

    func NewRenderer(baseDir string) (*Renderer, error)

      NewRenderer creates a new instance of Renderer

      func (*Renderer) Render

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

        Render implements echo.Render interface

        Source Files