Freemarker integration for NodeJS
JAVA_HOME
should be set properlynpm i freemarker -S
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.
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
node v6+
npm test
null
is not supported
MIT