Skip to content
A simple template engine for Node.js. Cacheable and Trackable.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test refactor Apr 5, 2013
.gitignore
LICENSE
README.md
package.json

README.md

node-pages

A simple template engine for Node.js.
Cacheable and Trackable.
You can make breakpoints on the debugger.

Installation

$ npm install node-pages

Example

template1.npg

<? if (arg) { ?>
  <p><?= arg.name ?></p>
<? } ?>

example.js

var pages = require('node-pages').create({
  srcPath : '/path/to/template1.npg'
});

var arg = {name : 'tasogare'};
var str = pages.render(arg);

Custom tags

Custom tags (e.g. <% %> )

var pages = require('node-pages').create({
  openWord : '<%',
  closeWord : '%>',
  srcPath : '/path/to/template2.npg'
});

template2.npg

<% if (arg) { %>
  <p><%= arg.name %></p>
<% } %>

Custom render arg name

Custom render arg name (e.g. it )

var pages = require('node-pages').create({
  renderArgName : 'it',
  srcPath : '/path/to/template3.npg'
});

var arg = {name : 'tasogare'};
var str = pages.render(arg);

template3.npg

<? if (it) { ?>
  <p><?= it.name ?></p>
<? } ?>

Html escaped and unescaped

  • Escaped with <?= val ?>
  • Unescaped with <?- val ?>

Options

  • srcPath Template file path
  • openWord Open tag. ("<?" is default.)
  • closeWord Close tag. ("?>" is default.)
  • renderArgName Render arg name. ("arg" is default.)
  • workDir Directory of compiled js file. ("node-pages/lib/work" is default.)

License

The MIT License

Something went wrong with that request. Please try again.