Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

egg-view-ejs

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-view-ejs

egg view plugin for ejs

Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
643
-39.62%
Maintainers
4
Weekly downloads
 
Created
Source

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 = function* () {
  yield 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 = function* () {
  const locals = {
    data: 'world',
  };

  const viewOptions = {
    layout: 'layout.ejs'
  };

  yield ctx.render('hello.ejs', locals, viewOptions);
};

Configuration

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT

Keywords

egg

FAQs

Package last updated on 27 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts