Release 3.0.0
egg view plugin for ejs.
$ npm i egg-view-ejs --save
// {app_root}/config/plugin.js exports.ejs = { enable: true, package: 'egg-view-ejs', }; // {app_root}/config/config.default.js exports.view = { mapping: { '.ejs': 'ejs', }, };
Create a ejs file
// app/view/hello.ejs hello <%= data %>
Render it
// app/controller/render.js exports.ejs = async ctx => { await ctx.render('hello.ejs', { data: 'world', }); };
The file will be compiled and cached, you can change config.ejs.cache = false to disable cache, it’s disable in local env by default.
config.ejs.cache = false
You can include both relative and absolute file.
Relative file is resolve from current file path.
// app/view/a.ejs include app/view/b.ejs <% include('b.ejs') %>
Absolute file is resolve from app/view.
app/view
// app/view/home.ejs include app/view/partial/menu.ejs <% include('/partial/menu.ejs') %>
You can render a view with layout also:
// app/view/layout.ejs <% body %> // app/controller/render.js exports.ejs = async ctx => { const locals = { data: 'world', }; const viewOptions = { layout: 'layout.ejs' }; await ctx.render('hello.ejs', locals, viewOptions); };
see config/config.default.js for more detail.
Please open an issue here.
MIT
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
egg-view-ejs
egg view plugin for ejs.
Install
Usage
Create a ejs file
Render it
The file will be compiled and cached, you can change
config.ejs.cache = falseto 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.
Absolute file is resolve from
app/view.Layout
You can render a view with layout also:
Configuration
see config/config.default.js for more detail.
Questions & Suggestions
Please open an issue here.
License
MIT