* docs: polish theme, playground, and reference pages Improve readability of the docs site with updated light/dark tokens, shared code-block styling, and playground editors that follow system color scheme. Skip CookieHub on localhost, serve the browser bundle from theme source, and use backtick titles on filter/tag reference pages for consistent navigation. Co-authored-by: Cursor <[email protected]> * docs: highlight npx in bash blocks and polish English copy Use Prism insertBefore for CLI commands like npx, tighten tutorial and reference wording, and keep YAML titles free of backticks so sidebar and page headings stay correct. Co-authored-by: Cursor <[email protected]> * docs: restore lowercase filter and tag titles Titles should match actual filter/tag identifiers (e.g. abs, append), not capitalized English labels. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]>
2.4 KiB
title
| title |
|---|
| Use in Express.js |
LiquidJS is compatible with Express template engines. You can set the LiquidJS instance as the view engine option:
var { Liquid } = require('liquidjs');
var engine = new Liquid();
// register liquid engine
app.engine('liquid', engine.express());
app.set('views', './views'); // specify the views directory
app.set('view engine', 'liquid'); // set liquid to default
{% note info Working Demo %} Here's a working demo for LiquidJS usage in Express.js: liquidjs/demo/express/.{% endnote %}
Template Lookup
The root option will continue to work as templates root, as you can see in Render A Template File. Additionally, the views option in express.js (as shown above) will also be respected. Say you have a template directory like:
.
├── views1/
│ └── hello.liquid
└── views2/
└── world.liquid
And you're setting template root for liquidjs to views1 and expressjs to views2:
var { Liquid } = require('liquidjs');
var engine = new Liquid({
root: './views1/'
});
app.engine('liquid', engine.express());
app.set('views', './views2'); // specify the views directory
app.set('view engine', 'liquid'); // set liquid to default
Both of hello.liquid and world.liquid can be resolved and rendered:
res.render('hello')
res.render('world')
Caching
Simply setting the cache option to true will enable template caching, as explained in Caching. It's recommended to enable cache in a production environment, which can be done by:
var { Liquid } = require('liquidjs');
var engine = new Liquid({
cache: process.env.NODE_ENV === 'production'
});