jspl
JSP Like Template Engine for ExpressJS and NodeJS (based on underscore, support include, cache...)
Features
- Cache
- Include HTML fragment
- Variables
- Loop
see: Gists section
Getting started
-
Install JSPL
$npm install jspl -save
-
Enable JSPL in Express 4
Edit app.js, let's JSPL bind to the express app.
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
// Enable
app.set('view cache', false);
// Bind JSPL to express
jspl.bind(app);
Sample: sample/express/
Gists
Add variable
File: views/index.html
Hello <%= name %>
File: app.js
app.get('/', function(req, res)
{
res.render('index', {name: 'John'});
})
Result:
Hello John
For loop
File: views/index.html
Hello
- <%= name %>
File: app.js
app.get('/', function(req, res)
{
res.render('index', {people: ['moe', 'curly', 'larry']});
})
Result:
Hello
- moe
- curly
- larry
Include fragment
Include a HTML page into the current one.
<%@ include file="viewName" %>
- viewName : Location of the included view without extension. The extension .html will be added automatically.
- <%@ %> : Indicate a tag
- include : Tag name
- file : Tag parameter
Notes
The simple template language is very close to JSP.
It's based on underscore.
This project does not provide any advanced JSP tag.
underscore. Compliant with Express. Add the tag include for HTML fragment.
Roadmap
- Improve syntax error message
- Speed optimization