Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including templator with all npm packages installed. Try it out:

var templator = require("templator")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

templator v1.1.0

Lightweight template engine

templator

Lightweight template engine.

js-semistandard-style

templator is a lightweight template engine featuring the following functionality:

  • Replaces {{property_name_1.property_name_2.etc}} with the value of the corresponding property data.property_name_1.property_name_2.etc of a data object passed as a parameter to the module's imported function.

  • Replaces {{> ./relative_path/file_name.ext}} with recursively rendered content of the target file.

  • Recursively renders all files in the srcFolder, except files with names starting with the _ symbol, and places the rendered files in the destFolder.

Installation

$ npm install templator --save-dev

Usage example

const templator = require('templator');
const data = getDataObjectSomehow();

templator(srcFolder, destFolder, data)
.then(() => {
  console.log('Success!');
})
.catch(err => {
  console.error(err);
});

API

templator(srcFolder, destFolder, data)

srcFolder {String} - Absolute or relative (to process.cwd()) path to the folder containing the templates.

destFolder {String} - Absolute or relative (to process.cwd()) path to the folder the rendered files to be saved in.

data {Object} - A data object to be used to replace {{property1.property2}} placeholders.

Returns {Promise<Void>}.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free