Global

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 module:ejs.localsName.

escape EscapeCallback <optional>
Options.escape

callback used to escape variables

include IncludeCallback <optional>

callback used to include files at runtime with include()

rethrow RethrowCallback <optional>
module:ejs-internal.rethrow

callback used to handle and rethrow errors

Source:
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

Source:
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

Source:
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 with () {} construct in the generated template functions. If set to false, data is still accessible through the object whose name is specified by module:ejs.localsName (default to locals).

strict Boolean <optional>
false

Whether to run in strict mode or not. Enforces _with=false.

destructuredLocals Array.<String> <optional>
[]

An array of local variables that are always destructured from module:ejs.localsName, available even in strict mode.

rmWhitespace Boolean <optional>
false

Remove all safe-to-remove whitespace, including leading and trailing whitespace. It also enables a safer version of -%> line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line).

client Boolean <optional>
false

Whether or not to compile a ClientFunction that can be rendered in the browser without depending on ejs.js. Otherwise, a TemplateFunction will be compiled.

escape EscapeCallback <optional>
module:utils.escapeXML

The escaping function used with <%= construct. It is used in rendering and is .toString()ed in the generation of client functions.

filename String <optional>

The filename of the template. Required for inclusion and caching unless you are using module:ejs.renderFile. Also used for error reporting.

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 filename to be set. Only works with rendering function.

context Object <optional>
this

The Object to which this is set during rendering.

scope Object <optional>
this

Alias of context. Deprecated.

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 null or undefined if there is an error

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
Source:

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.

Source:
Returns:

Return type depends on Options.async.

Type
String | Promise.<String>