Closed rvangundy closed 10 years ago
That's the way DOMBars is already working, unless I'm missing something else?
var template = DOMBars.compile('<div>{{firstname}} {{lastname}}</div>');
var dom = template({ firstname:'John', lastname:'Doe' });
Also, I've already written a precompiler for DOMBars.
Doh, yeah you're right. Just doing some upfront investigating and misread the lingo in the readme:
// Generate a template.
var template = DOMBars.compile(
'<input type="checkbox" checked="{{{test}}}">'
)({
test: false
});
// Append the template directly to the body element and watch the magic happen.
document.body.appendChild(template);
Coming off the Handlebars docs you'd expect something more like:
// Generate a template.
var template = DOMBars.compile('<input type="checkbox" checked="{{{test}}}">');
var context = {test: false};
document.body.appendChild(template(context));
So just a semantics issue. Cool library, time to dive in deeper than the docs :)
Haha, yeah. Thank you! I'll look at updating the docs and doing some maintenance tonight or tomorrow.
Wondering why this is the case? Original Handlebars works like:
Replacing the string output with an element in DOMbars, this pattern would allow reuse of the template function, but also would pave the way for a DOMbars pre compiler.