Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shopify-liquid

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shopify-liquid

Liquid template engine in Node.js (Shopify compliant)

  • 1.1.13
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

shopify-liquid

NPM version Build Status Coverage Status Dependency manager

A feature-rich Liquid implementation for Node.js, with compliance with Jekyll and Github Pages.

Installation:

npm install --save shopify-liquid

Render from String

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

Render from File

var engine = Liquid({
    root: path.resolve(__dirname, 'views/'),  // for layouts and partials
    extname: '.liquid',
    cache: false
});
// equivalent to: engine.renderFile("hello", {name: 'alice'});
var html = engine.renderFile("hello.liquid", {name: 'alice'});

cache default to false, extname default to .liquid, root default to "".

Use with Express.js

app.engine('liquid', engine.express());
app.set('views', './views');        // specify the views directory
app.set('view engine', 'liquid');   // register the template engine

Includes

// file: color.liquid
color: '{{ color }}' shape: '{{ shape }}'

// file: theme.liquid
{% assign shape = 'circle' %}
{% include 'color' %}
{% include 'color' with 'red' %}
{% include 'color', color: 'yellow', shape: 'square' %}

The output will be:

color: '' shape: 'circle'
color: 'red' shape: 'circle'
color: 'yellow' shape: 'square'

Layouts

// file: default-layout.liquid
Header
{% block content %}My default content{% endblock %}
Footer

// file: page.liquid
{% layout "default-layout" %}
{% block content %}My page content{% endblock %}

The output of page.liquid:

Header
My page content
Footer
  • It's possible to define multiple blocks.
  • block name is optional when there's only one block.

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/

All Tags

Documentation: https://shopify.github.io/liquid/basics/introduction/#tags

TagDocumentSourceTest
case/whenDocumentSourceTest
ifDocumentSourceTest
unlessDocumentSourceTest
elsif/elseDocumentSourceTest
forDocumentSourceTest
breakDocumentSourceTest
continueDocumentSourceTest
for: limit,offset,range,reversedDocumentSourceTest
cycleDocumentSourceTest
cycle: groupDocumentSourceTest
tablerowDocumentSourceTest
tablerow: cols,limit,offset,rangeDocumentSourceTest
assignDocumentSourceTest
captureDocumentSourceTest
incrementDocumentSourceTest
decrementDocumentSourceTest
rawDocumentSourceTest
commentDocumentSourceTest
includeDocumentSourceTest
layout, blockDocumentSourceTest

All Filters

Documentation: https://shopify.github.io/liquid/basics/introduction/#filters

FilterDocumentSourceTest
absDocumentSourceTest
appendDocumentSourceTest
capitalizeDocumentSourceTest
ceilDocumentSourceTest
dateDocumentSourceTest
defaultDocumentSourceTest
divided_byDocumentSourceTest
downcaseDocumentSourceTest
escapeDocumentSourceTest
escape_onceDocumentSourceTest
firstDocumentSourceTest
floorDocumentSourceTest
joinDocumentSourceTest
lastDocumentSourceTest
lstripDocumentSourceTest
mapDocumentSourceTest
minusDocumentSourceTest
moduloDocumentSourceTest
newline_to_brDocumentSourceTest
plusDocumentSourceTest
prependDocumentSourceTest
removeDocumentSourceTest
remove_firstDocumentSourceTest
replaceDocumentSourceTest
replace_firstDocumentSourceTest
reverseDocumentSourceTest
roundDocumentSourceTest
rstripDocumentSourceTest
sizeDocumentSourceTest
sliceDocumentSourceTest
sortDocumentSourceTest
splitDocumentSourceTest
stripDocumentSourceTest
strip_htmlDocumentSourceTest
strip_newlinesDocumentSourceTest
timesDocumentSourceTest
truncateDocumentSourceTest
truncatewordsDocumentSourceTest
uniqDocumentSourceTest
upcaseDocumentSourceTest
url_encodeDocumentSourceTest

Operators

Documentation: https://shopify.github.io/liquid/basics/operators/

==, !=, >, <, >=, <=, or, and, contains.

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:

Keywords

FAQs

Package last updated on 18 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc