1

i need to use phonegap for an android app, and i need to include a header file in every page, but i don't want to make it by scripting.

is there a way to do that (templating?), or i must use javascript to do that? i've seen this thread, but it's not what i'm looking for fully: jQuery and PhoneGap - Include a HTML file clientside with HTML or JS?

thanks all for answers

Community
  • 1
  • 1
Someoneinthe
  • 372
  • 1
  • 9

1 Answers1

1

There are many ways to include HTML on your pages (SSI, PHP, ASP, JS...). But because of PhoneGap (remember that PhoneGap doesn't act as a server) you cant use server side technologies to include HTML, so SSI, PHP and ASP are out.

JS is the only remaining valid option. Why do not you use it ? Anyway, you will have to use JS with the PhoneGap API.

The meaning of this operation is to avoid duplicating the code, right ?

David
  • 453
  • 3
  • 14
  • thanks for your answer! typically, i want to make header / footer templates, but how can i include that in a page wich haven't been loaded yet? i just don't want to duplicate code, of course! – Someoneinthe Jul 25 '13 at 09:28
  • I had the same problem a few months ago. In my opinion, you have two valid solutions : 1/ Use JS to include your HTML template 2/ Make a onepage website with different pages (jQuery mobile allows to do it that way) Code duplicating is always such a pain... If you choose the JS way of course you'll have to wait until the page is completely loaded to add to your DOM header and your footer. – David Jul 25 '13 at 09:43
  • i don't really have the choice! it will be one page + js tol oad what i need. thks for help – Someoneinthe Jul 25 '13 at 09:46
  • Et si tu trouves d'autres solutions je suis preneur également. Je continue de mon côté à tester et trouver LA meilleure solution pour ce genre de problème. (oui j'ai vu que ton profil était en Français c'est plus facile comme ça ^^) – David Jul 25 '13 at 09:49
  • ça marche! ce qui m’embête le plus c'est pour loader le header, j'aimerais pouvoir switcher entre 2 modeles facilement selon les pages, et pas avoir une grosse structure dont la moitié du code ne pas pas servir une fois sur 2.... – Someoneinthe Jul 25 '13 at 09:51
  • C'est sur que niveau optimisation c'est le must, d'autant plus que sur mobile les ressources ne sont pas les mêmes que sur un Desktop. – David Jul 25 '13 at 12:04