nunjucks-in-yaml
v1.0.4
Published
A YAML extension to use documents in YAML as Nunjucks templates.
Downloads
4
Maintainers
Readme
nunjucks-in-yaml
A YAML extension to use documents in YAML as Nunjucks templates.
Install
npm i nunjucks-in-yaml
Template example
A template files are --- # {name}
-separated YAML and nunjucks templates.
First section is YAML. Nunjucks templates follows it.
from: [email protected]
subject: Thank you for your message!
--- # text
Hi {{ user.name }},
Thank you for your message.
Best regards,
--- # html
Hi <b>{{ user.name }}<b>,
Thank you for your message.
Best regards,
Usage
const loader = require('nunjucks-in-yaml')
const user = {
name: 'Kurara',
email: '[email protected]'
}
const obj = loader.renderSync('test.yml', { user })
console.log(obj)
/* Output:
{
meta: { from: '[email protected]', subject: 'Thank you for your message!' },
text: '\r\nHi Kurara,\r\n\r\nThank you for your message.\r\n\r\nBest regards,\r\n',
html: '\r\nHi <b>Kurara<b>,\r\n\r\nThank you for your message.\r\n\r\nBest regards,\r\n'
}
*/