New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ejs-layout-chain

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ejs-layout-chain

ejs layout chain level

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-42.86%
Maintainers
1
Weekly downloads
 
Created
Source

ejs-layout-chain

Layout chain support for ejs in express 4.x

Installation

$ npm install ejs-layout-chain

Usage

var express = require('express');
var ejsLayoutChain = require('ejs-layout-chain');

var app = express();

app.set('view engine', 'ejs');

app.use(ejsLayoutChain);

app.get('/', function(req, res) {
  var locals = {
    title: 'Page Title',
    description: 'Page Description',
    header: 'Page Header',
    layout: 'layout>category'
  };
  res.render('news', locals);
});

app.listen(3000);

contentFor

For example, consider this view:

foo
<%- contentFor('pageSectionA') %>
bar
<%- contentFor('pageSectionB') %>
baz

Using it with this layout:

<div class="header"><%- pageSectionA %></div>
<div class="body"><%- body %></div>
<div class="footer"><%-defineContent('pageSectionB')%></div>

Will render:

<div class="header">bar</div>
<div class="body">foo</div>
<div class="footer">baz</div>

Notice that the difference between using <%- pageSectionA %> and <%-defineContent('pageSectionA')%> is that the former will generate an error if the view doesn't define content for this section.

Layout chain

If you want to specify the layout you want to render a view in, instead of specifying one layout, you can specify a layout chain like 'layout1>layout2', this will render view as body of layout2, then layout2 as body of layout1.

For example, consider this view:

foo
<%- contentFor('pageSectionA') %>
bar
<%- contentFor('pageSectionB') %>
baz

Using it with layout1:

<div class="layout1-header"><%- pageSectionA %></div>
<div class="layout1-body"><%- body %></div>
<div class="layout1-footer"><%-defineContent('pageSectionB')%></div>

layout2:

<div class="layout2-header"><%- pageSectionA %></div>
<div class="layout2-body"><%- body %></div>
<div class="layout2-footer"><%-defineContent('pageSectionB')%></div>
<%- contentFor('pageSectionA') %>
<%- pageSectionA %>
<%- contentFor('pageSectionB') %>
<%-defineContent('pageSectionB')%>

as:

  res.render('view', {layout: 'layout1>layout2'});

Will render:


<div class="layout1-header">bar</div>
<div class="layout1-body">
  <div class="layout2-header">bar</div>
  <div class="layout2-body">foo</div>
  <div class="layout2-footer">baz</div>
</div>
<div class="layout1-footer">baz</div>

Running tests

Clone the rep and run:

$ make test

License

MIT

Keywords

FAQs

Package last updated on 18 Oct 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc