
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
express-blocks
Advanced tools
Middleware for Express that adds basic block support to views.
This was initially prototyped by Laurie Harper. Thanks Laurie!
Easy peasy:
npm install express-blocks
Please note the version you install and only specify that exact version as your dependency while this is in development. Breaking changes are likely!
In your app.js
, register this middleware:
app.use(require('express-blocks'));
Then in your (top-level) layout, name and add placeholders for your desired
blocks
(e.g. in EJS syntax):
<%- blocks.foo %>
...
<%- blocks.bar %>
And from your views (or intermediate layouts), add arbitrary HTML to those
blocks via the block()
function:
<%- block('foo', '<p>Hello world!</p>') %>
You can use the helper script()
and stylesheet()
functions to generate
generate staple <script>
and <link rel="stylesheet">
references for you:
<%- script('/path/to/script.js') %>
<%- stylesheet('/path/to/stylesheet.js') %>
Which are exposed to (top-level) layouts as blocks named scripts
and
stylesheets
, also aliased globally just like body
:
<%- scripts %>
<%- stylesheets %>
As Borat would say, niiice!
Run the included Express example:
node example/app.js
Then open your browser to http://localhost:8080/ to see it in action.
You can verify that everything works as expected via:
npm test
If you want to submit a pull request, be sure to add a test case, too!
MIT License. Copyright © 2011 Aseem Kishore and Laurie Harper.
FAQs
Express middleware for blocks in views.
The npm package express-blocks receives a total of 2 weekly downloads. As such, express-blocks popularity was classified as not popular.
We found that express-blocks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.