Ran into this issue today. At work, data returned from CFCs have a bunch of content pre-pended. In regular tag-flow coding, this is super-simple to overcome:

<cfcontent type="text/plain" reset="true" />
<cfreturn mycontent />

Using the cfcontent tag, I can “[discard] output that precedes call to cfcontent” (from the docs :)). This strips out all the garbage that I don’t want, and returns only the awesome data that I need.

Since we’re getting ready to upgrade to CF9, however, I’ve been playing around with writing my ColdFusion components in the new 100% script-based syntax. One problem, though: there is no cfscript version of cfcontent, so I’m back to the original problem.

Fortunately, there is a solution. By tapping into the underlying Java methods that are exposed, we can easily recreate similar functionality. Here’s all it takes:

remote any function getdata() {
     getpagecontext().getcfoutput().clearall();   �
     return supersweetdata;
}

Nothing to it. And for future reference, take 5 minutes to dump out getpagecontext(). You can see all the nice methods that are available…who knows, you might just find something useful

Share this: