ejs-addon
v1.2.0
Published
Addons for ejs template engine
Downloads
190
Readme
ejs-addon
Addon for EJS 2.x and Express 4.x
Install
npm i ejs-addon -S
Usage
Explains the usages of ejs-addon
, you can view detail usages in example.
layout
layout
refers to ejs-mate
- Declare layout
<!DOCTYPE html>
<head>
<title>ejs-addon</title>
</head>
<body>
<%- body %>
</body>
- Use layout
<% layout('default') %>
<h1>Title</h1>
- Working with Express
const app = require('express')();
const engine = require('ejs-addon');
app.engine('ejs', engine);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
loader
- Use
loader
<% loader([
'/path/to/foo.css',
'/path/to/bar.js'
]) %>
- Declare placeholder in layout
ejs-addon
use <%- css %>
and <%- js %>
, put them in the right place.
<!DOCTYPE html>
<head>
<title>ejs-addon</title>
<%- css %>
</head>
<body>
<%- body %>
<%- js %>
</body>
More about loader
loader
support adding prefix for assets.
For example, if you are using CDN for your application in production, follow these steps:
- Ensure
process.env.NODE_ENV === 'productoin'
- Use the following lines of codes in your
app.js
:
// Pulic folder
app.set('public path', path.join(__dirname, 'public'));
// Declare CDN url pattern
app.set('public pattern', 'http://yourcdn.com/@version/@path');
Things about CDN pattern:
@version
would be replaced with the file's modified time@path
would be replaced with the files relative file path as you declared inloader()
Example
See example
Contribute
Fire an issue
License
The MIT License