All Projects → eggjs → Egg View Ejs

eggjs / Egg View Ejs

Licence: mit
egg view plugin for ejs.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Egg View Ejs

egg-rest
Restful API plugin for egg
Stars: ✭ 106 (+96.3%)
Mutual labels:  egg, egg-plugin
Egg Mongoose
Stars: ✭ 386 (+614.81%)
Mutual labels:  egg, egg-plugin
egg-session
session plugin for egg
Stars: ✭ 48 (-11.11%)
Mutual labels:  egg, egg-plugin
egg-userservice
userservice plugin for egg
Stars: ✭ 21 (-61.11%)
Mutual labels:  egg, egg-plugin
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 Graphql
Stars: ✭ 345 (+538.89%)
Mutual labels:  egg, egg-plugin
egg-view-pug
egg view plugin for pug.
Stars: ✭ 24 (-55.56%)
Mutual labels:  egg, egg-plugin
Egg Sequelize
Sequelize for Egg.js
Stars: ✭ 540 (+900%)
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-swagger
swagger-ui plugin for egg ,Demo:
Stars: ✭ 26 (-51.85%)
Mutual labels:  egg, egg-plugin
Egg Valid
👮Validation plugin for eggjs
Stars: ✭ 10 (-81.48%)
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-oracle
OracleDB plugin for egg
Stars: ✭ 23 (-57.41%)
Mutual labels:  egg, egg-plugin
Egg Mysql
MySQL plugin for egg
Stars: ✭ 276 (+411.11%)
Mutual labels:  egg, egg-plugin
egg-view-react
egg view plugin for react
Stars: ✭ 89 (+64.81%)
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

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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

MIT

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].