egg-view-liquid
egg view plugin for liquid.
Install
$ npm i egg-view-liquid --save
Usage
// {app_root}/config/plugin.jsexportsliquid = enable: true package: 'egg-view-liquid'; // {app_root}/config/config.default.jsexportsview = mapping: '.liquid': 'liquid' ; // liquid configexportsliquid = {};
Create a liquid file
// app/view/hello.liquidhello data
Render it
// app/controller/render.jsexportsliquid = async { await ctx;};
The file will be compiled and cached, you can change config.liquid.cache = false
to disable cache, it's disable in local env by default.
Include
You can include both relative and absolute file.
Relative file is resolve from current file path.
// app/view/a.liquid include app/view/b.liquid{% render 'view/b' %}
Absolute file is resolve from app/view
.
// app/view/home.liquid include app/view/partial/menu.liquid{% render 'partial/menu' %}
Tips:
-
Use when you need to import files:
partial/xxx
not/partial/xxx
-
LiquidJs currently does not support direct use of method calls in files:
Hello {{helper.data()}}
can be replaced with tags or plugins if needed. -
Now, if you want to use LiquidJs for like express-ejs-Layout's
contentfor
, just use LiquidJs'sblock
instead.
Configuration
see config/config.default.js for more detail.
Questions & Suggestions
Please open an issue here.