HenrikJoreteg / ICanHaz.js

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

Feature Request: Remote templates #1

Closed pixelmatrix closed 13 years ago

pixelmatrix commented 13 years ago

Would love to be able to link to template files instead of including them in the view directly. It feels weird to show the templates to the users.

Any plans for something like this?

HenrikJoreteg commented 13 years ago

Thanks for your feedback... didn't see this till just now, somehow (sorry).

So, I see your point about not exposing the templates to the users if they view the page source.

ICanHaz supports adding templates like so:

ich.addTemplate('templateName', 'MY_TEMPLATE_STRING');

So, there's nothing stopping you from making a server call to grab the templates. For example:

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

Then you'd just have to set up your server to create that JSON package with all your templates and template names.

I could however add support for that directly in ich. But, I kinda like bootstrapping all my templates with the original server call rather than having to load the page, then go back and load all the templates before being able to show anything to the user. Showing the templates is a bit of a downside I suppose, but you're not really exposing anything more than what they'd see by inspecting the DOM.

Curious to hear your thoughts though. Thanks again for writing.

HenrikJoreteg commented 13 years ago

I've added an example of how to do this to the documentation at http://icanhazjs.com.

I would prefer not to integrate this because I don't want to make the decision on how to serve up templates for the users. Thanks for the suggestion, nonetheless.

mgiacomi commented 12 years ago

Hi Henrik,

I understand that you don't want to push people in one direction or another with respect to remote template loading, but there might be a bigger picture here that you should consider. For example what about those of us using your framework on mobile phones. In frameworks like phonegap it is a benefit to have the whole app be a single page. In my case I end up with a index.html page with 50+ templates in it. My app does not connect to a server so I end up pointing to a local json file that I have to encode by hand with my templates. It works, but it is not pretty. It would be much easier if the framework allowed me to point to a files that included all of my templates, or a set of my templates. This way I could put all 50+ in one file, or break them up by module.

I'm not saying I like the current proposed solutions, but I think something that takes us SPI (http://en.wikipedia.org/wiki/Single-page_application) and SPI standalone (mobile) developer into consideration would be nice.

Just my 2 cents...

jdsampayo commented 12 years ago

+1 to this, also in Rhomobile would be useful to use the href of the script tag, as all is locally in the phone