PDA

View Full Version : Build HTML Document in Memory or Local File?



mtippin
23 Apr 2012, 12:26 PM
I'm working on a Sencha Touch 2 app that will collect various pieces of information from the user, merge that data into an existing HTML template (deployed as a resource file with the Sencha app), submit the resulting HTML document to an HTML-to-PDF web service such as www.docraptor.com and then display the resulting PDF to the user.

The twist in all of this is that the generated HTML document won't be displayed on-screen, and all of the XTemplate examples I've seen are focused on building dynamic HTML for display.

It seems my biggest initial hurdle is reading the HTML template out of a file and into memory where I can work with it as an XTemplate, then potentially saving the resulting HTML to a file on the local filesystem.

Can anyone point me in the right direction to get started? Any suggestions would be appreciated!

mitchellsimoens
25 Apr 2012, 5:30 AM
You can use Ext.Ajax.request to retrieve the HTML document. Saving to local filesystem can only be odne in a native wrapper like PhoneGap

mtippin
25 Apr 2012, 5:44 AM
I can use Ext.Ajax to retrieve an HTML template file that is deployed as part of the Sencha app? How would I do that?

If that works, then I'm well on my way - I'll have the text of the template as the Ajax response and can go to work doing text replacements using the user data collected in the app.

Will I be able to use the Ajax response text as the "source" for an XTemplate?

Saving the new file to the local filesystem via PhoneGap is no problem.

Thanks!

mitchellsimoens
25 Apr 2012, 6:08 AM
Loading via Ajax off the filesystem will not work, you will likely get a cross-origin error. I usually have a utility class for my apps that holds the templates.