/freemarker

Freemarker integration for NodeJS

Primary LanguageBatchfileMIT LicenseMIT

freemarker

NPM version

Freemarker integration for NodeJS

How to use

  • JAVA_HOME should be set properly
  • npm i freemarker -S

Render string

const Freemarker = require('freemarker');

const freemarker = new Freemarker();

freemarker.render('<h1>${title}</h1>', { title: 'test render' }, (err, result) => {
  if (err) {
    throw new Error(err);
  }
  console.log(result);
});

NOTICE: Don't use #include in string for rendering.

Render file

const Freemarker = require('freemarker');

const freemarker = new Freemarker({ root: __dirname });

freemarker.renderFile(path.join(__dirname, 'index.ftl'), data, (err, result) => {
  if (err) {
    throw new Error(err);
  }
  console.log(result);
});

In this example, path.join(__dirname, 'index.ftl') can be replaced with index or index.ftl

Test

node v6+

npm test

Known issues

  • null is not supported

LICENSE

MIT