Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple template engine for Node.js. Cacheable and Trackable.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 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.