0

Is there a way for Android to preprocess an html page (like PHP) using templates or whatever and then output the right HTML?

Example of what I mean.

Let's say I have a variable in android that holds a URL of an address or a file for JavaScript. I want to output the right script tags from Android preprocessing the file.

So in the Android activity there could be

String loc = "http://example.com/file.js"

and when I pass the loc using a webview JavascriptInterface thingy I want src from above to equal loc.

<script type="text/javascript" src="loc variable here"></script> //but how?

Also, dynamically add or remove scripts as needed. So, this sounds like a job for templates (like how Ruby On Rails ERB files work). But can Android do this? If so, how do you do it?

Thanks.

Scott Deutsch
  • 637
  • 1
  • 8
  • 24
  • AFAIK there is no built in support for HTML style templates like this natively within android. You'd either have to use something like `src=\""+locVar+"\"` or you'd have to write a template interpreter your self. If it doesn't need to do anything other than variable substitutions it would probably be fairly straight forward but if you want it to be able to evaluate arbitrary java code that will be more tricky. – FoamyGuy Apr 26 '13 at 02:22
  • Actually it looks like there might be a few options out there, they aren't part of native android APIs, but are 3rd party libraries that you could include See [Here](http://stackoverflow.com/questions/13349082/javascript-java-html-template-data-binding-library) and [Here](http://stackoverflow.com/questions/3583846/java-html-builder-anti-template-library) for 2 possibilities – FoamyGuy Apr 26 '13 at 02:25

1 Answers1

0

I ended up just using document.createElement("script") to dynamically load scripts instead of doing a template. It was a lot easier that way.

Scott Deutsch
  • 637
  • 1
  • 8
  • 24