eggjs / Egg View Ejs
Licence: mit
egg view plugin for ejs.
Stars: ✭ 54
Programming Languages
javascript
184084 projects - #8 most used programming language
Labels
Projects that are alternatives of or similar to Egg View Ejs
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-7.41%)
Mutual labels: egg, egg-plugin
egg-y-validator
☯️ Egg Magic Validator (Egg 魔法验证工具)
Stars: ✭ 30 (-44.44%)
Mutual labels: egg, egg-plugin
Egg Restfulapi
🏅 基于Egg.js 2.0 & {mongoose,jwt}RESTful API 模板,用于快速集成开发RESTful前后端分离的服务端。
Stars: ✭ 524 (+870.37%)
Mutual labels: egg, egg-plugin
egg-parameters
Merge all parameters (ctx.params, ctx.request.query, ctx.request.body) into ctx.params like Rails application.
Stars: ✭ 24 (-55.56%)
Mutual labels: egg, egg-plugin
egg-view-vue-ssr
Egg Vue Server Side Render (SSR) Plugin
Stars: ✭ 90 (+66.67%)
Mutual labels: egg, egg-plugin
egg-elasticsearch
elasticsearch client for egg.js
Stars: ✭ 22 (-59.26%)
Mutual labels: egg, egg-plugin
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+812.96%)
Mutual labels: egg, egg-plugin
Egg Cancan
cancancan like authorization plugin for Egg.js
Stars: ✭ 47 (-12.96%)
Mutual labels: egg, egg-plugin
egg-view-ejs
egg view plugin for ejs.
Install
$ npm i egg-view-ejs --save
Usage
// {app_root}/config/plugin.js
exports.ejs = {
enable: true,
package: 'egg-view-ejs',
};
// {app_root}/config/config.default.js
exports.view = {
mapping: {
'.ejs': 'ejs',
},
};
// ejs config
exports.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.
Include
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/home.ejs include app/view/partial/menu.ejs
<% include /partial/menu.ejs %>
Layout
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);
};
Configuration
see config/config.default.js for more detail.
Questions & Suggestions
Please open an issue here.
License
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].