import "."
Overview
Index
Examples
Subdirectories

Overview ▾

Package liquid is a pure Go implementation of Shopify Liquid templates.

It's intended for use in for use in https://github.com/osteele/gojekyll.

See the project README https://github.com/osteele/liquid for additional information and implementation status.

Example

Code:

engine := NewEngine()
template := `<h1>{{page.title}}</h1>`
scope := map[string]interface{}{
    "page": map[string]interface{}{
        "title": "Introduction",
    },
}
out, err := engine.ParseAndRenderString(template, scope)
if err != nil {
    log.Fatalln(err)
}
fmt.Println(out)

Output:

<h1>Introduction</h1>

Index ▾

Examples

Package

Package files

engine.go template.go

type Engine

Engine parses template source into renderable text.

type Engine interface {
    RegisterFilter(name string, fn interface{})
    RegisterTag(string, func(form string) (func(io.Writer, chunks.Context) error, error))

    ParseTemplate(text []byte) (Template, error)
    ParseAndRender(text []byte, bindings map[string]interface{}) ([]byte, error)
    ParseAndRenderString(text string, bindings map[string]interface{}) (string, error)
}

func NewEngine

func NewEngine() Engine

NewEngine returns a new engine.

type TagDefinition

type TagDefinition func(expr string) (func(io.Writer, chunks.Context) error, error)

type Template

Template renders a template according to scope.

Bindings is a map of liquid variable names to objects.

type Template interface {
    // Render executes the template with the specified bindings.
    Render(bindings map[string]interface{}) ([]byte, error)
    // RenderString is a convenience wrapper for Render, that has string input and output.
    RenderString(bindings map[string]interface{}) (string, error)
}

Subdirectories

Name Synopsis
..
chunks
errors
expressions
filters
generics
tags