kaola-fed / freemarker

Freemarker integration for NodeJS
MIT License
26 stars 17 forks source link

freemarker

NPM version

Freemarker integration for NodeJS

How to use

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

LICENSE

MIT