shopify-liquid
Liquid implementation for Node.js. All tags and filters listed in Shopify Documentation shall be implemented.
Shopify liquid is used by Jekyll and Github Pages.
Usage
Install:
npm install --save shopify-liquid
Parse and Render:
var Liquid = require('shopify-liquid');
var engine = Liquid();
engine.parseAndRender('{{name | capitalize}}', {name: 'alice'}); // Alice
Caching templates:
var tpl = engine.parse('{{name | capitalize}}');
engine.render(tpl, {name: 'alice'}); // Alice
Register Filters:
// Usage: {{ name | uppper }}
engine.registerFilter('upper', function(v){
return v.toUpperCase();
});
See existing filter implementations: https://github.com/harttle/shopify-liquid/blob/master/filters.js
Register Tags:
// Usage: {% upper name%}
engine.registerTag('upper', {
parse: function(tagToken, remainTokens) {
this.str = tagToken.args; // name
},
render: function(scope, hash) {
var str = Liquid.evalValue(this.str, scope); // 'alice'
return str.toUpperCase(); // 'Alice'
}
});
See existing tag implementations: https://github.com/harttle/shopify-liquid/blob/master/tags/
Operators
Documentation: https://shopify.github.io/liquid/basics/operators/
==, !=, >, <, >=, <=, or, and, contains.
Tags
Documentation: https://shopify.github.io/liquid/basics/introduction/#tags
| Tag | Document | Source | Test |
|---|---|---|---|
case/when |
Document | Source | Test |
if |
Document | Source | Test |
unless |
Document | Source | Test |
elsif/else |
Document | Source | Test |
for |
Document | Source | Test |
break |
Document | Source | Test |
continue |
Document | Source | Test |
for: limit,offset,range,reversed |
Document | Source | Test |
cycle |
Document | Source | Test |
cycle: group |
Document | Source | Test |
tablerow |
Document | Source | Test |
tablerow: cols,limit,offset,range |
Document | Source | Test |
assign |
Document | Source | Test |
capture |
Document | Source | Test |
increment |
Document | Source | Test |
decrement |
Document | Source | Test |
raw |
Document | Source | Test |
comment |
Document | Source | Test |
Filters
Documentation: https://shopify.github.io/liquid/basics/introduction/#filters
Differences from Shopify Liquid
url_encodeis based onencodeURIComponent,will be converted to%20.
Async Support
harttle/shopify-liquid do NOT support async rendering, this is by design.
The primary principle of harttle/shopify-liquid is EASY TO EXTEND. Async rendering introduces extra complexity in both implementation and extension.
For template-driven projects, checkout these Liquid-like engines:
