views:

129

answers:

1

Hey everyone, I would appreciate a pointing in the right direction with the problem I'm having. In short, I'm working on an application that will create PDFs using TinyMCE and ColdFusion 8. I have the ability to create a PDF by just entering in text, pictures, etc. However, I want to be able to import an html template and insert it into the TinyMCE .

Basically, I have a file directory code snippet that lets me browse through my 'HTMLTemplates' folder, and am able to select an HTML document. Now, I want to be able to take all the code from that selected HTML document and insert it into my TinyMCE box. Any tips on how I might do this, maybe?

Thanks!

+1  A: 

If I understood you correctly, you already have a TinyMCE plugin which pops up a window and allows you to browse the certain directory using existing cfm page which you render within the popup window. Right?

If not, you should start with this. Not sure how easy it is done in current version, but in the older TinyMCE I've created the custom upload plugin (needed to track the site security permissions for current user) pretty quickly.

Next, I can see two quick ways to pass the server file contents to the client-side:

  1. Make it available via HTTP so you can make the GET request and read contents into the variable.
  2. Output it on the page using CF (say, on form submit when file selected) and grab using JavaScript.

I'd personally tried the second option. After you grab the text into the variable you can put it into the TinyMCE using it's API.

It can be as simple as output escaped text into the hidden div with known ID and read it using DOM operations (assuming that there is cfoutput around):

<div id="myTemplate">#HTMLEditFormat(myFileContents)#</div>

Also you can output the text directly into the JavaScript variable (of cource, with accurate escaping), maybe like this.

<script type="text/javascript">
var text = '#HTMLEditFormat(myFileContents)#';
</script>

Most advanced and possibly better for performance (and definitely "cooler") way is to use the concept of script tags as data containers, like this:

<script type="text/plain">
#HTMLEditFormat(myFileContents)#
</script>

Last time I've seen this in Nadel's blog, I think. Read it, pretty interesting.

Hope this helps.

Sergii
Thank you Sergii, this helped me get started. I appreciate it
knawlejj