HenrikJoreteg / ICanHaz.js

A clean solution for templating with Mustache.js and jQuery or Zepto
icanhazjs.com
Other
838 stars 132 forks source link

GrabTemplates giving an error on html fragment containing templates #51

Open ttamminen opened 11 years ago

ttamminen commented 11 years ago

I have a complex user-interface inside a window (pop-up) and window content is a dynamically loaded html fragment.

The process is following

The problem is that when I open the window two or more times I get an error for each template that is used in the window.

Invalid name: dialogTitle. ICanHaz.js:472 ich.addTemplate

I understand that the problem is that the template is already "grabbed", but is there anyway to tell ICanHaz to either skip or override existing templates? There are quite many templates in the window, so it would be really nice if I could still use GrabTemplates and not manually check the existence and then add template if it doesn't exist in the ICanHaz.

This is slightly related to the issue opened by tonynoy https://github.com/HenrikJoreteg/ICanHaz.js/issues/44

HenrikJoreteg commented 11 years ago

Sorry this has been sitting forever. We could do something like this. I could see it being useful. I'd consider it if you have the time to write the code and send a PR.

HenrikJoreteg commented 11 years ago

It seems like grab templates should take an option {ignoreDuplicates: true}.

ttamminen commented 11 years ago

Sorry for not doing the fix. This has been in my mind even thou I have working in a project that is not using ICanHaz. :)

What if template has been updated and it has a same id? We would then override template with the latest. Should the option be: { overrideDuplicates: true } or silently update it without error?

On 27 May 2013 18:21, Henrik Joreteg notifications@github.com wrote:

It seems like grab templates should take an option {ignoreDuplicates: true}.

— Reply to this email directly or view it on GitHubhttps://github.com/HenrikJoreteg/ICanHaz.js/issues/51#issuecomment-18503565 .

sylvainpolletvillard commented 11 years ago

Same problem here.

I am building a full AJAX single page web app and new templates are grabbed at each ajax call just after injecting the HTML. So going back to a page already visited results in "Invalid name" errors in console as these templates already exist. I think ICaNHaz should override duplicates by default. People using same templates IDs on the same page, well, go to hell

HenrikJoreteg commented 11 years ago

I prefer being explicit in failing if there is one. But it would be easy enough to have it take an option to silently overwrite them. I stand by my original suggested fix. Can't do it right now, I've got 40 other things going at once, but a PR on this would get merged.