New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

express-ejs-extend

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-ejs-extend

Layouts support for EJS templates in Express 3+.

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
124
-6.77%
Maintainers
1
Weekly downloads
 
Created
Source

Express EJS Extend

Layouts support for EJS templates in Express 3+.

Usage

First, add it as engine in your app:

// server.js

var express = require('express'),
    path    = require('path');


var app = express();

app.engine('ejs', require('express-ejs-extend')); // add this line
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

app.get('/', function (req, res) {
  res.render('index', {title: 'world!'});
});

app.listen(3000);

Finally, in your views, call the extend function:

<%# views/index.ejs %>

<% extend('layout') %>

<h1>Hello <%= title %></h1>
<%# views/layout.ejs %>

<!DOCTYPE html>
<html>
<body>
<%- content %>
</body>
</html>

That's all, your GET / will render:

<!DOCTYPE html>
<html>
<body>
<h1>Hello world!</h1>
</body>
</html>

Notes:

  • In your view (the one that calls extend), you can surround the extend with any combination of (<% or <%-) and (%> or -%>).
  • In your layout, it's recommended to use exactly <%- content %> so the engine doesn't escape your HTML tags. Also you can end it with -%> instead to avoid any trailing \n.
  • The signature of extend is: extend(layout[, data]), so you can also pass an object with data and that will be passed to the layout.

License

This project is released under the MIT license.

Keywords

express

FAQs

Package last updated on 18 Nov 2016

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