template

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 9 Imported by: 0

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

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

Jump to

Keyboard shortcuts

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