Hi,
I'm trying to set a template engine based on Hogan.js like this:
engine.renderTemplateSource = function (templateSource, bindingContext, options) {
// Precompile and cache the templates for efficiency
var precompiled = templateSource['data']('precompiled');
if (!precompiled) {
precompiled = hogan.compile(templateSource.text());
templateSource['data']('precompiled', precompiled);
}
// Run the template and parse its output into an array of DOM elements
return ko.utils.parseHtmlFragment(precompiled.render(bindingContext.$data.test, {}));
};
It works great when using all the time named templates.
The problems start if I mix named templates with anonymous templates. Example:
<!-- my "home" template -->
<div class="home container">
<div>{{test}}</div>
<div data-bind="template: {foreach: items}">
<div>{{test}}</div>
</div>
</div>
Both home and anonymous templates are binded to view models which expose a field called "test". The value on each of those two view models is different.
The problem is that when processing the parent template, home, both {{test}} tags are evaluated and replaced with the value from the home view model.
Any ideas as to how to avoid this and get each {{test}} flag evaluated in its own bindingContext?
Thanks!