Methods
fileLoader(path) → {String|Object}
A file read function, similar to fs.readFileSync, this function can be read a file by path, return a string after processing
Parameters:
Name | Type | Description |
---|---|---|
path |
String | the path of the file to be read |
- Source:
Returns:
the contents of the file as a string or objects that implement the toString() method
- Type
- String | Object
Type Definitions
ClientFunction(localsopt, escapeopt, includeopt, rethrowopt) → {String|Promise.<String>}
This type of function is returned from module:ejs.compile
, when
Options
.client
is true.
This is also used internally to generate a
TemplateFunction
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
locals |
Object |
<optional> |
{} | an object of data to be passed into the template. The name of this variable
is adjustable through |
escape |
EscapeCallback |
<optional> |
Options .escape
|
callback used to escape variables |
include |
IncludeCallback |
<optional> |
callback used to include files at runtime with |
|
rethrow |
RethrowCallback |
<optional> |
module:ejs-internal.rethrow
|
callback used to handle and rethrow errors |
Returns:
Return type depends on Options
.async
.
- Type
- String | Promise.<String>
EscapeCallback(markup) → {String}
Escapes a string using HTML/XML escaping rules.
Parameters:
Name | Type | Description |
---|---|---|
markup |
String | Input string |
Returns:
Escaped string
- Type
- String
IncludeCallback(path, dataopt) → {String}
The callback called by ClientFunction
to include files at runtime with include()
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
String | Path to be included |
|
data |
Object |
<optional> |
Data passed to the template |
Returns:
Contents of the file requested
- Type
- String
Options
Compilation and rendering options.
Type:
- Object
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
debug |
Boolean |
<optional> |
false | Log generated JavaScript source for the EJS template to the console. |
compileDebug |
Boolean |
<optional> |
true | Include additional runtime debugging information in generated template functions. |
_with |
Boolean |
<optional> |
true | Whether or not to use |
strict |
Boolean |
<optional> |
false | Whether to run in strict mode or not.
Enforces |
destructuredLocals |
Array.<String> |
<optional> |
[] | An array of local variables that are always destructured from |
rmWhitespace |
Boolean |
<optional> |
false | Remove all safe-to-remove whitespace, including leading and trailing
whitespace. It also enables a safer version of |
client |
Boolean |
<optional> |
false | Whether or not to compile a |
escape |
EscapeCallback |
<optional> |
module:utils.escapeXML
|
The escaping function used with |
filename |
String |
<optional> |
The filename of the template. Required for inclusion and caching unless
you are using |
|
root |
String | Array.<String> |
<optional> |
The path to the template root(s). When this is set, absolute paths for includes (/filename.ejs) will be relative to the template root(s). |
|
openDelimiter |
String |
<optional> |
'<' | The opening delimiter for all statements. This allows you to clearly delinate the difference between template code and existing delimiters. (It is recommended to synchronize this with the closeDelimiter property.) |
closeDelimiter |
String |
<optional> |
'>' | The closing delimiter for all statements. This allows to to clearly delinate the difference between template code and existing delimiters. (It is recommended to synchronize this with the openDelimiter property.) |
delimiter |
String |
<optional> |
'%' | The delimiter used in template compilation. |
cache |
Boolean |
<optional> |
false | Whether or not to enable caching of template functions. Beware that the options of compilation are not checked as being the same, so special handling is required if, for example, you want to cache client and regular functions of the same file. Requires |
context |
Object |
<optional> |
this | The Object to which |
scope |
Object |
<optional> |
this | Alias of |
async |
Boolean |
<optional> |
false | Whether or not to create an async function instead of a regular function. This requires language support. |
- Source:
RenderFileCallback(errnullable, stropt, nullable)
Callback for receiving data from module:ejs.renderFile
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
err |
Error |
<nullable> |
error, if any resulted from the rendering process |
str |
String |
<optional> <nullable> |
output string, is |
- Source:
RethrowCallback(err, str, filename, lineno, esc)
This type of callback is used when Options
.compileDebug
is true, and an error in the template is thrown. By default it is used to
rethrow an error in a better-formatted way.
Parameters:
Name | Type | Description |
---|---|---|
err |
Error | Error object |
str |
String | full EJS source |
filename |
String | file name of the EJS file |
lineno |
Number | line number of the error |
esc |
EscapeCallback |
TemplateFunction(localsopt) → {String|Promise.<String>}
This type of function is returned from module:ejs.compile
, when
Options
.client
is false.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
locals |
Object |
<optional> |
{} | an object of data to be passed into the template. |
Returns:
Return type depends on Options
.async
.
- Type
- String | Promise.<String>