Using the template loader
Steven, I looked into the template loader for use with jsRender. I did not attempt to use it yet, just read the instructions. I don't get how the rendering call works since you have 2 items, the template and the data. But the examples I'm looking at for jsRender use the jQuery function like this which takes 3 params. $("#movieContainer").html($("#movieTemplate").render(my.vm.movies[1]));
I'm a little confused. And I did take a quick look at the examples but they don't seem jsRender specific.
tia, Bill
Hey Bill,
You should be able to follow the instructions on the readme to get it working with jsRender, that is the engine I originally built it for and like to use. I will give you a quick walk-through here based on the code you posted to help you get up and running.
First, inside of your
tag, add this code:<link rel="template/jsrender" type="text/html" href="movieTemplate.html" />
Notice how the "rel" attribute says "template/jsrender", that's how the library knows which template engine to use. Also, the library gets the name of the template from the filename without the extension. Now, in your javascript, you can do this:
tmplLoader.ready(function() {
// this code gets run after the templates have been loaded.
$("#movieContainer").html(tmplLoader.render("movieTemplate", my.vm.movies[1]));
});
It's a bit different than using jsRender directly, but the idea behind my library is to abstract the details of loading and rendering the template away from the developer so you don't have to worry about it. Keep in mind also that you can use this with a different template engine by simply changing the "rel" attribute in your tag to the correct engine. Hope that helps!
Sincerely, Steven Hunt