Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 27 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2009, 01:00 AM   PM User | #31
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Whoa whoa whoa, #1, don't use <cfcontent> at all. If you want to know what it actually does, then read about it in the CF livedocs, but otherwise Ben Nadel (the guru that he is) is just using it really as a hack to suppress every little wee-bit of whitespace. If you were to use it in all of your cfincludes, it would actually remove the outputted content of all includes before the one that was currently processing, and thus you would only be left with the outputted content of the last cfinclude.

I really recommend just using <cfsilent>, and just wrapping it around all of your "processing" code at the top of the page.
Code:
<cfsilent>

   <!--- suppressed output code goes here (cfsets, queries, whatever).  No line breaks will be kept in the output --->
   <cfset myVar1 = "Test">
   <cfset myVar2 = "Test 2">

</cfsilent>(Line break 1)
(Line break 2)
<!DOCTYPE ...  >
<html>
blah blah blah rest of the page
That will only leave you with two linebreaks at the top of the page, unless you really wanted to be crazy and put the <!doctype> tag right next to your </cfsilent>, then that would suppress those two extra line breaks, but reduce your source code readability (which of course, is fail).

Otherwise, use the <cfsetting> tag with enableCFOutputOnly="yes" (or "true" for the attribute value, whatever you prefer).
Ex:
Code:
<cfsetting enableCFOutputOnly="yes">

Absolutely everything in the template is not added to the output buffer, 
UNLESS that text is between a <cfoutput> and a </cfoutput> tag.
This text itself is not added to the output buffer, and will not be sent to the client's browser.

<cfoutput>This text WILL be added to the output buffer, and WILL be sent to the client's browser.</cfoutput>
I actually do just that on simple pages meant for returning JSON data to an AJAX call. Here's an example directly from production code on my site. Don't mind the code that you might not understand, it's just an example of using enableCFOutputOnly.
Code:
<cfsetting enableCFOutputOnly="yes">

<cfset user = application.UserManager.getUser( form.userID )>

<!--- Return JSON object to client. --->
<cfoutput>
{
  userID: #user.getUserID()#,
  firstName: "#jsStringFormat( user.getFirstName() )#",
  lastName: "#jsStringFormat( user.getLastName() )#"
}
</cfoutput>
Only the text wrapped in the <cfoutput> tag will be returned to the client.

Hope that helps.

Greg
Gjslick is offline   Reply With Quote
Old 12-08-2009, 01:25 AM   PM User | #32
wyclef
Regular Coder

 
Join Date: Feb 2005
Posts: 149
Thanks: 1
Thanked 0 Times in 0 Posts
wyclef is an unknown quantity at this point
yea that helps. maybe i'll just live with a few lines. i got the cfoutput thing to work it's just that it wants me to escape every damn # sign and I use those for html entities throughout the content so it's a total pain in the arse and seems completely impractical so I guess I'll just stick with cfsilent. that will at least cut back on the half the breaks and just live with 2 breaks b4 doctype and hope they upgrade their servers to 9.1. thx for yer help man, this has been a crazy rollercoaster of whitespace madnesssssssss
wyclef is offline   Reply With Quote
Old 12-08-2009, 01:43 AM   PM User | #33
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Lol, tell me about it... But yeah, that's much more practical with the <cfsilent> tags then, rather than having to escape all of your # signs.

Good luck buddy, and lemme know if you need anything else.

Greg
Gjslick is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:57 AM.


Advertisement
Log in to turn off these ads.