Custom Tag JavaScript Problem

Word Count: 563

I am working on a custom tag that creates presentation using JavaScript. When you create this tag you will set a bunch of attributes and everything in between the tag is our content. Here is an example of what I need to do. In my custom tag there can be any amount of html.

<cfimport prefix="tags" taglib="mytags">
<tags:test att1="one" att2="two">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas ante lectus, mollis eget, rutrum sit amet, venenatis quis, quam. Sed posuere massa et leo. Ut sodales arcu at nulla. Cras tempus sagittis ligula. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam ante urna, vehicula eu, scelerisque ac, aliquam ac, magna. Etiam quis pede at est eleifend dapibus. Integer tristique, tellus sit amet malesuada iaculis, justo urna cursus nisl, a convallis lacus risus eget orci. Etiam elit arcu, pulvinar id, mollis in, mollis in, nibh. Quisque tincidunt. Proin dapibus tellus non nulla. Integer et metus. Praesent viverra, sapien id blandit tempor, est orci viverra diam, in molestie enim eros sed diam. Quisque dolor enim, fermentum sed, egestas eu, semper eget, sapien. Donec in diam. Morbi cursus gravida est. Donec eleifend metus eu purus. Nam mattis nisl ac lorem.</p>
<br /><br />
<p>Nam venenatis, pede vitae commodo tristique, eros diam rhoncus ante, ut porta dolor pede fringilla magna. Proin pretium euismod massa. Integer at dolor. In mollis risus sed arcu. Vestibulum tortor est, lobortis non, imperdiet a, mollis eget, libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Vivamus vel sapien. Ut facilisis convallis purus. Nulla facilisi. Quisque non lectus sit amet quam facilisis pharetra. Etiam dolor enim, auctor venenatis, dignissim a, scelerisque feugiat, erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
<br /><br />
<p>Etiam varius eros eu arcu egestas fringilla. Fusce dignissim lorem at felis. Aenean aliquet, tellus in adipiscing laoreet, elit nisl eleifend dui, et interdum turpis leo nec felis. Mauris at arcu vel ante ornare elementum. Ut vehicula arcu sed ligula. Vivamus sollicitudin dui. Nunc nec quam vel tortor molestie rutrum. Suspendisse quis eros ac elit luctus convallis. Cras malesuada. Cras ac orci.</p>   
</tags:test>

The problem in my case is I was trying to use thistag.generatedContent inside a script block. When JavaScript comes across this content it is an illegal string. Fortunately there is method for exactly this problem. The toScript() method will allow us to take a ColdFusion variable and convert it to a js variable. Here is all I had to do to fix the problem. The method will take the ColdFusion variable as the first argument and the js variable name you wish to assign the conversion to.

toScript(thistag.GeneratedContent,"html")

Comments

#1 Posted By: Justin Carter Posted On: 1/6/08 6:53 PM
Hah, I was trying to do the exact same thing a few days ago with generated content and Ext! At the time I threw in the towel when I ran up against the line break issue, because I was without documentation and without internet access... And who really codes while they're on a holiday anyway? :D
#2 Posted By: Dan Vega Posted On: 1/6/08 7:02 PM |
Author Comment
I hope we are not working on the same project. If you are trying to create a window custom tag it might be already done! ha


Post Your Comment







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.