pongo: github.com/flosch/pongo Index | Files

package pongo

import "github.com/flosch/pongo"

Pongo implements a Django-syntax-like templating engine.

See the tests for examples.

Index

Package Files

context.go doc.go expr.go filters.go helper.go tags.go template.go

Variables

var Filters = map[string]FilterFunc{
    "safe":        filterSafe,
    "unsafe":      nil,
    "lower":       filterLower,
    "upper":       filterUpper,
    "capitalize":  filterCapitalize,
    "default":     filterDefault,
    "trim":        filterTrim,
    "length":      filterLength,
    "join":        filterJoin,
    "striptags":   filterStriptags,
    "time_format": filterTimeFormat,
    "floatformat": filterFloatFormat,
}
var Tags = map[string]*TagHandler{
    "if":        &TagHandler{Execute: tagIf, Ignore: tagIfIgnore},
    "else":      nil,
    "endif":     nil,
    "for":       &TagHandler{Execute: tagFor, Ignore: tagForIgnore},
    "endfor":    nil,
    "block":     &TagHandler{Execute: tagBlock},
    "endblock":  nil,
    "extends":   &TagHandler{},
    "include":   &TagHandler{},
    "trim":      &TagHandler{Execute: tagTrim, Ignore: tagTrimIgnore},
    "endtrim":   nil,
    "remove":    &TagHandler{Execute: tagRemove, Ignore: tagRemoveIgnore},
    "endremove": nil,
}

type Context Uses

type Context map[string]interface{}

A Context is used to pass data to the template. You can pass whatever you want in interface{}.

type FilterChainContext Uses

type FilterChainContext struct {
    // Store what you want along the filter chain. Every filter has access to this store.
    Store map[string]interface{}
    // contains filtered or unexported fields
}

func (*FilterChainContext) HasVisited Uses

func (ctx *FilterChainContext) HasVisited(names ...string) bool

type FilterFunc Uses

type FilterFunc func(interface{}, []interface{}, *FilterChainContext) (interface{}, error)

type TagHandler Uses

type TagHandler struct {
    Execute func(*string, *executionContext, *Context) (*string, error)
    Ignore  func(*string, *executionContext) error
    Prepare func(*tagNode, *Template) error
}

type Template Uses

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

func FromFile Uses

func FromFile(file_path string, locator templateLocator) (*Template, error)

Reads a template from file. If there's no templateLocator provided, one will be created to search for files in the same directory the template file is located. file_path can either be an absolute filepath or a relative one.

func FromString Uses

func FromString(name string, tplstr *string, locator templateLocator) (*Template, error)

Creates a new template instance from string.

func Must Uses

func Must(t *Template, err error) *Template

The Must function is a little helper to create a template instance from string/file. It checks whether FromString/FromFile returns an error; if so, it panics. If not, it returns the template instance. Is's primarily used like this:

var tplExample = template.Must(template.FromFile("example.html", nil))

func (*Template) Execute Uses

func (tpl *Template) Execute(ctx *Context) (out *string, err error)

Executes the template with the given context (can be nil).

func (*Template) ExecuteRW Uses

func (tpl *Template) ExecuteRW(w http.ResponseWriter, ctx *Context) error

Executes the template with the given context and writes to http.ResponseWriter on success. Context can be nil. Nothing is written on error; instead the error is being returned.

func (*Template) SetDebug Uses

func (tpl *Template) SetDebug(d bool)

pongo will print out a stacktrace whenever it panics if set to true.

Package pongo imports 11 packages (graph) and is imported by 8 packages. Updated 2018-12-03. Refresh now. Tools for package owners.