https://github.com/caseywebdev/underscore-express
Use Underscore templates easily in Express.
https://github.com/caseywebdev/underscore-express
Last synced: 9 months ago
JSON representation
Use Underscore templates easily in Express.
- Host: GitHub
- URL: https://github.com/caseywebdev/underscore-express
- Owner: caseywebdev
- License: mit
- Created: 2013-02-12T19:44:59.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2015-09-23T15:44:18.000Z (almost 11 years ago)
- Last Synced: 2025-09-19T12:35:44.651Z (10 months ago)
- Language: JavaScript
- Size: 3.77 MB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# underscore-express
Use Underscore templates easily in Express.
## Install
This package is registered in npm as `underscore-express`, so a simple...
```bash
npm install underscore-express
```
...will do it.
## Usage
In your Express app setup...
```js
// To use the default 'tmpl' extension...
require('underscore-express')(app);
// Or set your own...
require('underscore-express')(app, 'ut');
```
...and that's it!
## Including Subtemplates
`underscore-express` comes with a baked in include method. Here's an example...
**views/header.tmpl**
```tmpl
Header!
```
**views/footer.tmpl**
```tmpl
```
**views/index.tmpl**
```tmpl
<%= include('header') %>
Welcome to my homepage!
<%= include('footer') %>
```
**app.js**
```js
res.render('index');
```
**RESULT**
```html
Header!
Welcome to my homepage!
```
`include` is relative to the file it is called from. Feel free to use relative paths like `../../some/other/subtemplate`.