chipmunk-template
v1.2.0
Published
Super simple template renderer
Downloads
2
Readme
Chipmunk
Super simple template renderer
install:
npm i chipmunk-template
or
yarn add chipmunk-template
Example: https://furuholmanton.github.io/Chipmunk/
Usage
<template id="tpl">
<div class="div">
<p>{{ text }}</p>
<span>{{ span }}</span>
</div>
<p>{{ obj.complex }} {{ obj.nest.as.deep.as.you.want }}</p>
</template>
import render from 'chipmunk-template';
const data = {
text: 'Success!',
span: 'This text is rendered by JS.',
obj: {
complex: 'Nesting also ',
nest: {
as: {
deep: {
as: {
you: {
want: 'works',
}
}
}
}
}
}
}
const newHTML = render('#tpl', data);
document.body.innerHTML += newHTML;
Other possibilities
const newHTML = render(document.getElementById('tpl'), data);
const newHTML = render(`
<div class="div">
<p>{{ text }}</p>
<span>{{ span }}</span>
</div>
<p>{{ obj.complex }} {{ obj.nest.as.deep.as.you.want }}</p>
`, data);