Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-ejs-layouts

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-ejs-layouts

Layout support for ejs in express.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by10.26%
Maintainers
2
Weekly downloads
 
Created
Source

express-ejs-layouts

Layout support for ejs in express.

build status

Installation

npm install express-ejs-layouts

Usage

var express = require('express')
  , app = express()
  , expressLayouts = require('express-ejs-layouts')

app.set('view engine', 'ejs')
app.set('layout', 'myLayout') // defaults to 'layout'     

app.use(expressLayouts)
app.use(app.router)

app.get('/', function(req, res){
  res.render('aView', { layout: 'someSpecificLayout' })
})

app.listen(3000)

contentFor

A view

somebody
<%- contentFor('foo') %>
club
<%- contentFor('bar') %>
fight

With a layout

<%-bar%> <%-foo%>
<%-body%>

Renders

fight club
somebody

Script blocks extraction

If you like to place all the script blocks at the end, you can do it like this:

app.set("layout extractScripts", true)

A view

something<script>somejs<script>something

With a layout

...
<body>
<%- body %>
<%- script %>
</body>

Renders

...
<body>
somethingsomething
<script>somejs<script>
</body>

Enabling invididually:

req.render('view', { parseScript: true })

Optional sections

In a layout, you can have optional sections using defineContent: Unspecified section content defaults to ''.

1
<%-defineContent('a')%>
2
<%-defineContent('b')%>
3

with a view:

<%- contentFor('a') %>
1.5

will render:

1
1.5
2
3

Running tests

Clone the rep

make test

License

MIT

Keywords

FAQs

Package last updated on 26 May 2014

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