{"id":13413849,"url":"https://github.com/osteele/liquid","last_synced_at":"2025-05-15T10:00:40.241Z","repository":{"id":22159193,"uuid":"95456498","full_name":"osteele/liquid","owner":"osteele","description":"A Liquid template engine in Go","archived":false,"fork":false,"pushed_at":"2024-11-06T12:36:32.000Z","size":3175,"stargazers_count":298,"open_issues_count":31,"forks_count":58,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-14T15:56:52.530Z","etag":null,"topics":["golang","golang-package","liquid","liquid-templating-engine","template-engine"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/osteele/liquid","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osteele.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-26T14:39:52.000Z","updated_at":"2025-03-14T04:28:37.000Z","dependencies_parsed_at":"2024-06-18T13:39:53.878Z","dependency_job_id":"ff315627-3809-4f6c-8c09-fc9214e738a6","html_url":"https://github.com/osteele/liquid","commit_stats":{"total_commits":414,"total_committers":23,"mean_commits":18.0,"dds":"0.13285024154589375","last_synced_commit":"f432a255f14fe644eb764254983c932f277c58a5"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fliquid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fliquid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fliquid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fliquid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osteele","download_url":"https://codeload.github.com/osteele/liquid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319715,"owners_count":22051072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","golang-package","liquid","liquid-templating-engine","template-engine"],"created_at":"2024-07-30T20:01:51.111Z","updated_at":"2025-05-15T10:00:39.621Z","avatar_url":"https://github.com/osteele.png","language":"Go","readme":"# Liquid Template Parser\n\n[![go badge][go-svg]][go-url]\n[![Golangci-lint badge][golangci-lint-svg]][golangci-lint-url]\n[![Go Report Card badge][go-report-card-svg]][go-report-card-url]\n[![Go Doc][godoc-svg]][godoc-url]\n[![MIT License][license-svg]][license-url]\n\n`liquid` is a pure Go implementation of [Shopify Liquid\ntemplates](https://shopify.github.io/liquid). It was developed for use in the\n[Gojekyll](https://github.com/osteele/gojekyll) port of the Jekyll static site\ngenerator.\n\n\u003c!-- TOC --\u003e\n\n- [Liquid Template Parser](#liquid-template-parser)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Command-Line tool](#command-line-tool)\n  - [Documentation](#documentation)\n    - [Status](#status)\n    - [Drops](#drops)\n    - [Value Types](#value-types)\n    - [References](#references)\n  - [Contributing](#contributing)\n    - [Contributors](#contributors)\n    - [Attribution](#attribution)\n  - [Other Implementations](#other-implementations)\n    - [Go](#go)\n    - [Other Languages](#other-languages)\n  - [License](#license)\n\n\u003c!-- /TOC --\u003e\n\n## Installation\n\n`go get gopkg.in/osteele/liquid.v1` # latest snapshot\n\n`go get -u github.com/osteele/liquid` # development version\n\n## Usage\n\n```go\nengine := liquid.NewEngine()\ntemplate := `\u003ch1\u003e{{ page.title }}\u003c/h1\u003e`\nbindings := map[string]any{\n    \"page\": map[string]string{\n        \"title\": \"Introduction\",\n    },\n}\nout, err := engine.ParseAndRenderString(template, bindings)\nif err != nil { log.Fatalln(err) }\nfmt.Println(out)\n// Output: \u003ch1\u003eIntroduction\u003c/h1\u003e\n```\n\nSee the [API documentation][godoc-url] for additional examples.\n\n### Command-Line tool\n\n`go install gopkg.in/osteele/liquid.v0/cmd/liquid` installs a command-line\n`liquid` executable. This is intended to make it easier to create test cases for\nbug reports.\n\n```bash\n$ liquid --help\nusage: liquid [FILE]\n$ echo '{{ \"Hello World\" | downcase | split: \" \" | first | append: \"!\"}}' | liquid\nhello!\n```\n\n## Documentation\n\n### Status\n\nThese features of Shopify Liquid aren't implemented:\n\n- Filter keyword parameters, for example `{{ image | img_url: '580x', scale: 2\n  }}`. [[Issue #42](https://github.com/osteele/liquid/issues/42)]\n- Warn and lax [error modes](https://github.com/shopify/liquid#error-modes).\n- Non-strict filters. An undefined filter is currently an error.\n\n### Drops\n\nDrops have a different design from the Shopify (Ruby) implementation. A Ruby\ndrop sets `liquid_attributes` to a list of attributes that are exposed to\nLiquid. A Go drop implements `ToLiquid() any`, that returns a proxy\nobject. Conventionally, the proxy is a `map` or `struct` that defines the\nexposed properties. See \u003chttp://godoc.org/github.com/osteele/liquid#Drop\u003e for\nadditional information.\n\n### Value Types\n\n`Render` and friends take a `Bindings` parameter. This is a map of `string` to\n`any`, that associates template variable names with Go values.\n\nAny Go value can be used as a variable value. These values have special meaning:\n\n- `false` and `nil`\n  - These, and no other values, are recognized as false by `and`, `or`, `{% if\n    %}`, `{% elsif %}`, and `{% case %}`.\n- Integers\n  - (Only) integers can be used as array indices: `array[1]`; `array[n]`, where\n    `array` has an array value and `n` has an integer value.\n  - (Only) integers can be used as the endpoints of a range: `{% for item in\n    (1..5) %}`, `{% for item in (start..end) %}` where `start` and `end` have\n    integer values.\n- Integers and floats\n  - Integers and floats are converted to their join type for comparison: `1 ==\n    1.0` evaluates to `true`.  Similarly, `int8(1)`, `int16(1)`, `uint8(1)` etc.\n    are all `==`.\n  - [There is currently no special treatment of complex numbers.]\n- Integers, floats, and strings\n  - Integers, floats, and strings can be used in comparisons `\u003c`, `\u003e`, `\u003c=`,\n    `\u003e=`. Integers and floats can be usefully compared with each other. Strings\n    can be usefully compared with each other, but not with other values. Any\n    other comparison, e.g. `1 \u003c \"one\"`, `1 \u003e \"one\"`, is always false.\n- Arrays (and slices)\n  - An array can be indexed by integer value: `array[1]`; `array[n]` where `n`\n    has an integer value.\n  - Arrays have `first`, `last`, and `size` properties: `array.first ==\n    array[0]`, `array[array.size-1] == array.last` (where `array.size \u003e 0`)\n- Maps\n  - A map can be indexed by a string: `hash[\"key\"]`; `hash[s]` where `s` has a\n    string value\n  - A map can be accessed using property syntax `hash.key`\n  - Maps have a special `size` property, that returns the size of the map.\n- Drops\n  - A value `value` of a type that implements the `Drop` interface acts as the\n    value `value.ToLiquid()`. There is no guarantee about how many times\n    `ToLiquid` will be called. [This is in contrast to Shopify Liquid, which\n    both uses a different interface for drops, and makes stronger guarantees.]\n- Structs\n  - A public field of a struct can be accessed by its name: `value.FieldName`, `value[\"fieldName\"]`.\n    - A field tagged e.g. `liquid:”name”` is accessed as `value.name` instead.\n    - If the value of the field is a function that takes no arguments and\n      returns either one or two arguments, accessing it invokes the function,\n      and the value of the property is its first return value.\n    - If the second return value is non-nil, accessing the field panics instead.\n  - A function defined on a struct can be accessed by function name e.g.\n    `value.Func`, `value[\"Func\"]`.\n    - The same rules apply as to accessing a func-valued public field.\n  - Note that despite being array- and map-like, structs do not have a special\n    `value.size` property.\n- `[]byte`\n  - A value of type `[]byte` is rendered as the corresponding string, and\n    presented as a string to filters that expect one. A `[]byte` is not\n    (currently) equivalent to a `string` for all uses; for example, `a \u003c b`, `a\n    contains b`, `hash[b]` will not behave as expected where `a` or `b` is a\n    `[]byte`.\n- `MapSlice`\n  - An instance of `yaml.MapSlice` acts as a map. It implements `m.key`,\n    `m[key]`, and `m.size`.\n\n### References\n\n- [Shopify.github.io/liquid](https://shopify.github.io/liquid)\n- [Liquid for Designers](https://github.com/Shopify/liquid/wiki/Liquid-for-Designers)\n- [Liquid for Programmers](https://github.com/Shopify/liquid/wiki/Liquid-for-Programmers)\n- [Help.shopify.com](https://help.shopify.com/themes/liquid)\n\n## Contributing\n\nBug reports, test cases, and code contributions are more than welcome.\nPlease refer to the [contribution guidelines](./CONTRIBUTING.md).\n\n### Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://osteele.com/\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/674?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eOliver Steele\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=osteele\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/osteele/liquid/commits?author=osteele\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#ideas-osteele\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#infra-osteele\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/osteele/liquid/pulls?q=is%3Apr+reviewed-by%3Aosteele\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e \u003ca href=\"https://github.com/osteele/liquid/commits?author=osteele\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/thessem\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/973593?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJames Littlejohn\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=thessem\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/osteele/liquid/commits?author=thessem\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/osteele/liquid/commits?author=thessem\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://nosmileface.ru\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/12567?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ensf\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=nsf\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/osteele/liquid/commits?author=nsf\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://tobias.salzmann.berlin/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/796084?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTobias Salzmann\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=Eun\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/bendoerr\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/253068?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBen Doerr\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=bendoerr\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://daniil.it/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/7339644?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDaniil Gentili\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=danog\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/carolynvs\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1368985?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eCarolyn Van Slyck\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=carolynvs\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/kke\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/224971?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKimmo Lehto\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=kke\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://vito.io/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/77198?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eVictor \"Vito\" Gama\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/osteele/liquid/commits?author=heyvito\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the\n[all-contributors](https://github.com/kentcdodds/all-contributors)\nspecification. Contributions of any kind welcome!\n\n### Attribution\n\n| Package                                             | Author          | Description          | License            |\n|-----------------------------------------------------|-----------------|----------------------|--------------------|\n| [Ragel](http://www.colm.net/open-source/ragel/)     | Adrian Thurston | scanning expressions | MIT                |\n| [gopkg.in/yaml.v2](https://github.com/go-yaml/yaml) | Canonical       | MapSlice             | Apache License 2.0 |\n\nMichael Hamrah's [Lexing with Ragel and Parsing with Yacc using\nGo](https://medium.com/@mhamrah/lexing-with-ragel-and-parsing-with-yacc-using-go-81e50475f88f)\nwas essential to understanding `go yacc`.\n\nThe [original Liquid engine](https://shopify.github.io/liquid), of course, for\nthe design and documentation of the Liquid template language. Many of the tag\nand filter test cases are taken directly from the Liquid documentation.\n\n## Other Implementations\n\n### Go\n\n- [karlseguin/liquid](https://github.com/karlseguin/liquid) is a dormant\n  implementation that inspired a lot of forks.\n- [acstech/liquid](https://github.com/acstech/liquid) is a more active fork of\n  Karl Seguin's implementation.\n- [hownowstephen/go-liquid](https://github.com/hownowstephen/go-liquid)\n\n### Other Languages\n\n See Shopify's [ports of Liquid to other environments](https://github.com/Shopify/liquid/wiki/Ports-of-Liquid-to-other-environments).\n\n## License\n\nMIT License\n\n[coveralls-url]: https://coveralls.io/r/osteele/liquid?branch=master\n[coveralls-svg]: https://img.shields.io/coveralls/osteele/liquid.svg?branch=master\n\n[go-url]: https://github.com/osteele/liquid/actions?query=workflow%3A%22Build+Status%22\n[go-svg]: https://github.com/osteele/liquid/actions/workflows/go.yml/badge.svg\n\n[golangci-lint-url]: https://github.com/osteele/liquid/actions?query=workflow%3Lint\n[golangci-lint-svg]: https://github.com/osteele/liquid/actions/workflows/golangci-lint.yml/badge.svg\n\n[godoc-url]: https://godoc.org/github.com/osteele/liquid\n[godoc-svg]: https://godoc.org/github.com/osteele/liquid?status.svg\n\n[license-url]: https://github.com/osteele/liquid/blob/master/LICENSE\n[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg\n\n[go-report-card-url]: https://goreportcard.com/report/github.com/osteele/liquid\n[go-report-card-svg]: https://goreportcard.com/badge/github.com/osteele/liquid\n","funding_links":[],"categories":["Template Engines","Go","模板引擎","\u003cspan id=\"模板引擎-template-engines\"\u003e模板引擎 Template Engines\u003c/span\u003e","模板引擎`模版渲染和模版生成处理库`","Relational Databases"],"sub_categories":["HTTP Clients","查询语","HTTP客户端","高級控制台界面","Other Software","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流","Advanced Console UIs","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosteele%2Fliquid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosteele%2Fliquid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosteele%2Fliquid/lists"}