Customize knockout patterns
I have a page that requires jQuery.tmpl but I want to use knockout templates for
data-bind="foreach: Comments"
attribute. Since I have included jQuery.tmpl, the legacy templating template is disabled; is there a way i can force the native functionality?
thank
+3
Jon Bates
source
to share
1 answer
You cannot use foreach
or other control flow bindings in the jQuery.tmpl template.
However, if you want to call a named template and force it to use its own templating engine, then you would do something like:
<div data-bind="template: { name: 'itemsTmpl', templateEngine: new ko.nativeTemplateEngine() }">
</div>
<script id="itemsTmpl" type="text/html">
<ul data-bind="foreach: items">
<li data-bind="text: $data"></li>
</ul>
</script>
or cache a copy of the built-in templating engine ( new ko.nativeTemplateEngine()
) in a variable.
+5
RP Niemeyer
source
to share