liquidjs
A simple, expressive, safe and Shopify compatible template engine in pure JavaScript. The purpose of this repo is to provide a standard Liquid implementation for the JavaScript community so that Jekyll sites, Github Pages and Shopify templates can be ported to Node.js without pain.
- Documentation
- Please star LiquidJS on GitHub!
- Support LiquidJS on Open Collective or Patreon
Installation
Install from npm in Node.js:
npm install --save liquidjs
Or use the UMD bundle from jsDelivr:
<script src="https://cdn.jsdelivr.net/npm/liquidjs/dist/liquid.min.js"></script>
More details, refer to The Setup Guide.
Differences with Shopify/liquid
All features, filters and tags in shopify/liquid are supposed to be built in LiquidJS, but not those business-logic specific filters/tags which are typically from Shopify themes (see Plugins List in case you're looking for them and feel free to add yours to the list). Though being compatible the Ruby version is one of our priorities, there are still some differences:
- Dynamic file locating (enabled by default), that means layout/partial names are treated as variables in liquidjs. See #51.
- Truthy and Falsy. All values except
undefined,null,falseare truthy, whereas in Ruby Liquid all exceptnilandfalseare truthy. See #26. - Number. In JavaScript we cannot distinguish or convert between
floatandinteger, see #59. And when appliedsizefilter, numbers always return 0, which is 8 for integer in ruby, cause they do not have alengthproperty. - .to_liquid() is replaced by
.toLiquid() - .to_s() is replaced by JavaScript
.toString() - Iteration order for objects. The iteration order of JavaScript objects, and thus LiquidJS objects, is a combination of the insertion order for string keys, and ascending order for number-like keys, while the iteration order of Ruby Hash is simply the insertion order.
- Sort stability. The sort stability is also not defined in both shopify/liquid and LiquidJS, but it's considered stable for LiquidJS in Node.js 12+ and Google Chrome 70+.
Related Packages
- gulp-liquidjs: A shopify compatible Liquid template engine for Gulp using liquidjs.
- grunt-liquify: A Grunt task to process Liquid using liquidjs. Use it to add Liquid magic to your scripts and css assets.
- react-liquid: Liquid templating language component for React
- @11ty/eleventy: A simpler static site generator. An alternative to Jekyll. Written in JavaScript. Transforms a directory of templates (of varying types) into HTML.
Backers
If you love LiquidJS or your company is using LiquidJS? Please consider support us on Open Collective or Patreon.
Contributors ✨
Want to contribute? see Contribution Guidelines. Thanks goes to these wonderful people: