Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 3 FirstFirst 123
Results 31 to 33 of 33

Thread: cfincludes

  1. #31
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    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

  2. #32
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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

  3. #33
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    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


 
Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •