Reputation: 153
I have this file test.html:
<script id="entry-template" type="text/x-handlebars-template">
template content
</script>
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
In this way I can see my template correctly, but since I have a lot of template to implement, I would like to put this part
<script id="entry-template" type="text/x-handlebars-template">
template content
</script>
into an external file.
I am using phonegap, then I can't use server side language. Is Handlebarsjs a good thing to implement template in phonegap ? Maybe is better if I will load the template (only when I need it) using jquery.load ?
Thanks
Upvotes: 2
Views: 2332
Reputation: 3316
yes you can use handlebar js with this Plugin-in and manage your in template file in separate folder. Since browser doesn't allow local file load in browser because of origin null for that in mac
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
in Window add argument --allow-file-access-from-files in shortcut and then open
Upvotes: 0
Reputation: 7653
I can think of two answers for you here.
First you can load the file from an external source using ajax. This external source could be your web server, or it could even be a public folder of your dropbox. This will let you update the app in the future. The external source could also be a file on your phone, loaded by phone gap. Here is an example: loading handlebars.js template from external html file shows nothing
The second way is you could write a custom phonegap-native handler and inject raw html into a javascript function. For instance the first paramater would be the filename, and the second would be the entire html as a string. then load that string as a template.
Upvotes: 1