An async rendering template engine used by Pajamas. PJS syntax is based on EJS and can handle asynchronous templates easily.
Installation
npm install pjs-template
Usage
var pjs = ; pjs;// orpjs;// orvar template = pjs;;
With Express.js:
app;app;// You can use 'view options' to set the pjs optionsapp;
Example
Template hello.pjs
:
<%var foo = 'bar';;%>Hello <%= foo %>!
Render the file:
var pjs = ; pjs;
The done()
method tell PJS that it's an async block and to wait until done() is called.
If your block is not asynchronous, you don't need to use it:
<% var foo = 'bar'; %>Hello <%= foo %>!
Will display Hello bar!
Options
cache
(boolean) - Compiled functions are cached, requiresfilename
option when used with therender
methodfilename
- Used by cache to key caches, and for includeswatchFiles
(boolean) - Requirecache: true
, watch for changes on the cached files to clear their cache automaticallydebug
- Output generated function bodycompileDebug
- When false no debug instrumentation is compileddelimiter
- Character to use with angle brackets for open/closeescapeFunction
- Custom function for escaping HTML
Tags
<%
'Scriptlet' tag, for control-flow, no output<%=
Outputs the value into the template (HTML escaped)<%-
Outputs the unescaped value into the template<%#
Comment tag, no execution, no output<%%
Outputs a literal '<%'%>
Plain ending tag-%>
Trim-mode ('newline slurp') tag, trims following newline
Includes
Includes are relatives to the template with the include
call.
<% include /hellopjs %>
Customer Delimiters
Custom delimiters can be applied on a per-template basis, or globally:
var pjs = users = 'geddy' 'neil' 'alex'; // Just one templatepjs; // Or globallypjsdelimiter = '$';pjs;
Methods
- pjs.renderFile(path [, data] [, opts], callback)
- pjs.render(str [, data] [, opts], callback)
- pjs.compile(str [, opts])
- pjs.clearCache()
- pjs.escape(html)