Reputation: 128
I am having a problem with the new anonymous template engine. It cannot use nested templates. I get the error: "This template engine does not support anonymous templates nested within its templates".
My question: how do I force knockoutJS to use the jquery templates engine and not the new one. (until it also supports nested templates off course)
Thank you
Kindest regards Jan
Upvotes: 8
Views: 2259
Reputation: 114792
A couple things that should help clear this up:
foreach
, if
, ifnot
, and with
within it. You can still use the template binding (including nested templates).ko.setTemplateEngine()
. You would pass an instance of the engine that you want to use like ko.setTemplateEngine(new ko.nativeTemplateEngine)
templateEngine
parameter.So, for your case, you would likely want to remove the reference to jquery.tmpl.js, so that the native template engine is being used by default. The native template engine does support nested templates (anonymous or named).
Quick sample showing a named template with anonymous templates inside of it using the native template engine: http://jsfiddle.net/rniemeyer/GXFYB/
Upvotes: 21
Reputation: 13278
I got this problem when I removed the include to the tmpl js library but re-adding it fixed the problem. Are you sure you have included the jquery.tmpl.js library?
<script src='..<some path>../jquery.tmpl.js")' type="text/javascript"></script>
Also, I include the tmpl library first and the knockout library second. Maybe this is a factor?
Upvotes: 0