Skip to main content
December 24, 2008
Answered

Failure with cfsetting and cfprocessingdirective?

  • December 24, 2008
  • 17 replies
  • 1687 views
I have the following code buried deeply in our application. I've tried to reproduce a simpler example without success. This example clearly fails. What can I do to get the cfsetting and cfprocessingdirective tags to work correctly?

The code:

<cfsavecontent variable='AlsVar'><cfprocessingdirective suppresswhitespace='yes'>before<CFSETTING ENABLECFOUTPUTONLY="yes">
<cfloop index="i" from="1" to="6" step="1">
<cfif i mod 2>
#i# is Als odd<br>

<cfelse>

#i# is Als even<br>

</cfif>

</cfloop>
<CFSETTING ENABLECFOUTPUTONLY="no">after</cfprocessingdirective>
</cfsavecontent>
<cfmail from="support@uniformmarket.com" to="al@uniformmarket.com" subject="ProcessTag:#strElementName#">#AlsVar#</cfmail>

The content of the email that I get is:

before
#i# is Als odd<br>



#i# is Als even<br>


#i# is Als odd<br>



#i# is Als even<br>


#i# is Als odd<br>



#i# is Als even<br>

after

Which shows that both tags are being ignored: There is output outside the cfoutput tag AND the irregular spacing shows that whitespace is not being suppressed.

As stated, when I try simpler examples, it works and the documentation says that a "yes" in either tag overrides any number of previous "no"s!
This topic has been closed for replies.
Correct answer
I found the BUG in <CFSETTING ENABLECFOUTPUTONLY="yes">!!

<cfoutput> does not propagate to the code inside a <cfinclude> (thank goodness).

However, <CFSETTING ENABLECFOUTPUTONLY="yes"> thinks they do!

To demonstrate exactly how insidious this is, I have created three simple files to demonstrate the bug. This shows that "cleaning up" the <cfoutput> before a single <cfinclude> doesn't work. The middle file, "testinc.cfm" carefully does not surround the important <cfinclude> with <cfoutput>, but this is not enough! You would have to find EVERY occurrence and clean them all up, even inside modules you may not control, to get around the bug!!!

test.cfm:
------------------------
<cfoutput>
Works:<br>
</cfoutput>
<cfinclude template="testinc.cfm"><br>
<cfoutput>
<br>
Fails:<br>
<cfinclude template="testinc.cfm"><br>
</cfoutput>
------------------------

testinc.cfm:
-----------------------
<cfoutput>code<br></cfoutput>
<cfinclude template="testinc2.cfm">
-----------------------

testinc2.cfm:
-----------------------
<cfset NoCfoutput="YesCfoutput">Before:#NoCfoutput#<br><CFSETTING ENABLECFOUTPUTONLY="yes">
**** BEGIN INSIDE ENABLECFOUTPUTONLY="yes" ****<br>
Variable NoCfoutput is #NoCfoutput#<br>
**** END INSIDE ENABLECFOUTPUTONLY="yes" ****<br>
<CFSETTING ENABLECFOUTPUTONLY="no">After:#NoCfoutput#<br>
-----------------------

17 replies

Inspiring
December 27, 2008
> now that i actually ran you code, that's not what i'm getting on cf8. all i see is:
>
> beforeaft

Also confirmed for me on CFMX7.0.2 and CF8.

So - Al - what version of CF are you seeing this on?

--
Adam
Inspiring
December 27, 2008
Al Baker wrote:
> The content of the email that I get is:
>
> before
> #i# is Als odd<br>
>
>
>
> #i# is Als even<br>
>
>
> #i# is Als odd<br>
>
>
>
> #i# is Als even<br>
>
>
> #i# is Als odd<br>
>
>
>
> #i# is Als even<br>
>
> after

now that i actually ran you code, that's not what i'm getting on cf8. all i see is:


beforeafter
December 26, 2008
But, that is exactly where we NEED it suppressed? Otherwise the tags are generating HUGE HTML files!

That being the case, how DO we suppress the white space and non-cfoutput content? (Without duplicating the code, and maintenance nightmare, in 273 (and growing) different online stores, that is!)
Inspiring
December 26, 2008
Al Baker wrote:
> What?

from the docs: "You cannot use this tag to suppress output from a tag library."

December 25, 2008
The point is that without the <cfoutput></cfoutput> nothing should have been output! The #i# isn't being resolved because the code is NOT inside paired cfoutput tags.

Thus, nothing should have been generated inside the:

<CFSETTING ENABLECFOUTPUTONLY="yes">
...
<CFSETTING ENABLECFOUTPUTONLY="no">

But, because the code IS being generated, this smells like a bug. If it is, I need to know what triggers the bug because the code shown ALWAYS fails and yet when I try to create simple test cases, they ALWAYS work!

Therefore, *something* is making the CF interpreter erroneously ignore the <CFSETTING ENABLECFOUTPUTONLY="yes"> tag!!!!

Ditto for <cfprocessingdirective suppresswhitespace='yes'>!!!!

What?
Inspiring
December 25, 2008
Where are your <cfotuput> tags: around the whole lot? There's none in your
example code, so that's what I'm having to ass-u-me.

Put your <cfotuput> tags around just the bits you want to output, eg:

<cfoutput>#i# is Als odd<br></cfoutput>

--
Adam
Inspiring
December 25, 2008
the way i usually structure similar code is:

<cfprocessingdirectvive>
<cfsetting>
<cfsavecontent><cfoutput>
...
</cfoutput></cfsavecontent>
<cfsetting>
</cfprocessingdirective>

in many cases dealing with creating content for emails or XML/CSV/etc
files, you still need to carefully control whitespace in your code
inside <cfsavecontent> block...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/