Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knockoutjs 1.3PRE "This template engine does not support anonymous templates nested within its templates"

Tags:

knockout.js

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

like image 977
Jan Vercauteren Avatar asked Nov 28 '11 10:11

Jan Vercauteren


1 Answers

A couple things that should help clear this up:

  • If you reference jquery.tmpl.js before Knockout.js, then KO will set the jQueryTmplTemplateEngine as the default.
  • The jQueryTmplTemplateEngine does not support anonymous templates. This means that you can't use the control-flow bindings like foreach, if, ifnot, and with within it. You can still use the template binding (including nested templates).
  • You can control the default template engine by calling ko.setTemplateEngine(). You would pass an instance of the engine that you want to use like ko.setTemplateEngine(new ko.nativeTemplateEngine)
  • You can also pass the template engine to the template binding in the 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/

like image 186
RP Niemeyer Avatar answered Sep 27 '22 19:09

RP Niemeyer