4

I read on ICanHaz.js documentation that i should load templates from a remote like this

$.getJSON('/myserver/templates.json', function (templates) {
    $.each(templates, function (template) {
        ich.addTemplate(template.name, template.template);
    });
});

I have no idea how the json template should look like, would really appreciate an example ICanHaz.js json template.

Thanks

Ludvig
  • 637
  • 6
  • 18
  • 2
    I belive it's an array of objects with structure: `{name:'bla/bla/bla', template: 'template string <%= whatever %>'}`, that maybe you dynamically create by reading a directory tree of templates. – clyfe Dec 30 '11 at 18:06
  • oh yes ofcourse, im so dumb! Thanks for helping. – Ludvig Dec 30 '11 at 18:20

1 Answers1

3

To save some time on debugging $.each requires two arguments to the callback function: iterator and actual object

$.getJSON('/myserver/templates.json', function (templates) {        
    $.each(templates, function (id, template) {
        ich.addTemplate(template.name, template.template);
    });        
});

Of course you must remember to set promise since these templates are loaded in async mode.

opengrid
  • 1,942
  • 4
  • 16
  • 25