Did you know you could do this?

65 views
Skip to first unread message

Jesse Shaffer

unread,
Jun 19, 2015, 10:20:49 AM6/19/15
to lu...@googlegroups.com
So, I just found some interesting methods related to content buffering in the page context that either slipped in recently, or I had been (not so) blissfully unaware of until now.  I imagine this is what cfsavecontent uses under the hood, but using these methods directly gives you more control over when to start/stop output buffering.  It also works in ACF 11 (not sure about previous versions).

index.cfm
<cfscript>

writeoutput("before buffering begins");

buffer = GetPageContext().pushBody(); // push a new jsp writer onto the stack and return the top

writeoutput("buffered text - this will not make it out to the browser");

// GetPageContext().getOut() will return the writer that is on top of the stack, so right now, it will return the same object as "buffer"

GetPageContext().popBody(); // note, this pops the top writer off the stack, and returns whatever what underneath it...
// also, if you do not pop the body, it gets flushed to the output stream, as though you never began buffering

bufferedText = buffer.getString();

</cfscript>

Anyways, I thought it was something cool.  Definitely useful for what I'm wanting to do.
Reply all
Reply to author
Forward
0 new messages