Is it possible to define a view template in a javascript variable, instead of a script tag or a file?
Something like this:
var template = "< h1 ><%= title %> < / h1 >";
var rendered = can.view.render(template, data);
Ok, after a lot of research, because it isn't written in documentation, I found how to do it. The trick is that you have to register your template with an id first. If you are using a script tag or url to find a template, this step is done automatically by canJS.
So, if you want to render a template, stored in a variable, you have to do something like this:
var template = "< h1 ><%= title %> < / h1 >";
can.view.ejs('my-view-id', template);
var rendered = can.view.render('my-view-id', data);
Now you have the document fragment in rendered
.