Node.js port of the Liquid template engine
This is a port of the original Liquid template engine from Ruby to Node.js. It uses Promises to support non-blocking/asynchronous variables, filters, and blocks.
- Supports asynchronous variables, tags, functions and filters (helpers)
- Supports whitespace control
- Allows custom tags and filters to be added
- Supports full liquid syntax
- Based on original Ruby code
- High test coverage
``html
{% for product in products %}
{{ product.name }}
Only {{ product.price | price }}
{{ product.description | prettyprint | paragraph }}
{% endfor %}
`
`sh`
npm install liquid
Liquid supports a very simple API based around the Liquid.Engine class.
For standard use you can just pass it the content of a file and call render with an object.
`js
const Liquid = require('liquid')
const engine = new Liquid.Engine()
engine
.parse('hi {{name}}')
.then(template => template.render({ name: 'tobi' }))
.then(result => console.log(result))
// or
engine
.parseAndRender('hi {{name}}', { name: 'tobi' })
.then(result => console.log(result))
`
`js`
app.get((req, res, next) => {
engine
.parseAndRender('hi {{name}}', { name: 'tobi' })
.nodeify((err, result) => {
if (err) {
res.end('ERROR: ' + err)
} else {
res.end(result)
}
})
})
`javascript`
engine.registerFilters({
myFilter: input => {
return String(input).toUpperCase()
}
})
Take a look at the existing tags
to see how to implement them.
`js
class MyTag extends Liquid.Tag {
render () {
return 'hello world'
}
}
engine.registerTag('MyTag', MyTag)
`
`sh`
npm test
* harttle/liquidjs (liquidjs on npm) is another actively maintained Liquid parser and render for Node.jsliquid-node` wrapped to run in a browser.
* darthapo's Liquid.js is liquid ported to JavaScript to be run within the browser. It doesn't handle asynchrony.
* tchype's Liquid.js is
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!