Documentation ¶
Overview ¶
Package liquid is a pure Go implementation of Shopify Liquid templates, for use in https://github.com/osteele/gojekyll.
See the project README https://github.com/osteele/liquid for additional information and implementation status.
Note that the API for this package is not frozen. It is *especially* likely that subpackage APIs will change drastically. Don't use anything except from a subpackage except render.Context.
Example ¶
engine := NewEngine() template := `<h1>{{ page.title }}</h1>` bindings := map[string]interface{}{ "page": map[string]string{ "title": "Introduction", }, } out, err := engine.ParseAndRenderString(template, bindings) if err != nil { log.Fatalln(err) } fmt.Println(out)
Output: <h1>Introduction</h1>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTemplateError ¶
IsTemplateError returns a boolean indicating whether the error indicates an error in the template. All other errors are either errors in added tags or filters, or errors the implementation of this package.
Use this to avoid coding the specific types of subpackage errors, which are likely to change.
Types ¶
type Drop ¶
type Drop interface {
ToLiquid() interface{}
}
Drop indicates that the object will present to templates as its ToLiquid value.
Example ¶
// type redConvertible struct{} // // func (c redConvertible) ToLiquid() interface{} { // return "red" // } engine := NewEngine() bindings := map[string]interface{}{ "drop": redConvertible{}, } template := `{{ drop }}` out, err := engine.ParseAndRenderString(template, bindings) if err != nil { log.Fatalln(err) } fmt.Println(out)
Output: red
type Engine ¶
type Engine interface { // RegisterFilter defines a filter function e.g. {{ value | filter: arg }}. RegisterFilter(name string, fn interface{}) // RegisterTag defines a tag function e.g. {% tag %}. RegisterTag(string, Renderer) RegisterBlock(string, Renderer) ParseTemplate([]byte) (Template, error) // ParseAndRender parses and then renders the template. ParseAndRender([]byte, Bindings) ([]byte, error) // ParseAndRenderString is a convenience wrapper for ParseAndRender, that has string input and output. ParseAndRenderString(string, Bindings) (string, error) }
An Engine parses template source into renderable text.
An engine can be configured with additional filters and tags.
Filters ¶
RegisterFilter defines a Liquid filter.
A filter is any function that takes at least one input, and returns one or two outputs. If it returns two outputs, the second must be an error.
type Template ¶
type Template interface { // Render executes the template with the specified bindings. Render(Bindings) ([]byte, error) // RenderString is a convenience wrapper for Render, that has string input and output. RenderString(Bindings) (string, error) SetSourcePath(string) SetSourceLocation(string, int) }
A Template renders a template according to scope.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package evaluator defines methods such as sorting, comparison, and type conversion, that apply to interface types.
|
Package evaluator defines methods such as sorting, comparison, and type conversion, that apply to interface types. |
Package expression parses and evaluates the expression language that is used in objects {{a.b[c]}} and tag parameters {%assign pages = site.pages | reverse%}.
|
Package expression parses and evaluates the expression language that is used in objects {{a.b[c]}} and tag parameters {%assign pages = site.pages | reverse%}. |
Package filters defines the standard Liquid filters.
|
Package filters defines the standard Liquid filters. |
Package render parses and evaluates template strings.
|
Package render parses and evaluates template strings. |
Package tags defines the standard Liquid tags.
|
Package tags defines the standard Liquid tags. |