ColdFusion Isn't YELLING Today
Posted on September 25, 2007 at 8:49 PM in ColdFusion
So the other day I posted about CF YELLING all the time. Today I experienced quite the opposite - whispering. Actually, completely quiet is more like it. No output to the screen. Nothing.
So ColdFusion has this really awesome tag to get rid of the extra whitespace:
- <cfsilent>
- a
- b
- c
- d
- e
- f
- g
- h
- i
- <cfoutput>What did you expect to see?</cfoutput>
- </cfsilent>
Run that code above, and you'll see absolutely nothing on the screen.
And then there's this other really cool tag that helps with the same problem, but in a slightly different way:
- <cfsetting enablecfoutputonly="yes" />
- a
- b
- c
- d
- e
- f
- g
- h
- i
- <cfoutput>What did you expect to see?</cfoutput>
- <cfsetting enablecfoutputonly="no" />
This little snippet will result in the following being rendered to the screen:
What did you expect to see?
Now then, I use both of these tags on a daily basis. In fact, I use them many times each day. I use <cfsilent> tags in virtually every .cfm file that I write.
"So then, Quack," you ask, "what seems to be the problem? You obviously know what they do, and you apparently have plenty of experience with them. What epiphany could you have possibly had today over them?"
Well, I wouldn't call it an epiphany exactly. More like a "WTF?" I kinda got caught with my pants down, so-to-speak, tracing down a problem that I created by using them. It took me awhile, but I finally figured out what was causing my issue, which is cool. The problem is, I don't yet understand why it behaves this way.
Let me explain the scenario...
I have a regular .cfm template (web page) that uses <cfmodule /> to call a custom tag. The custom tag then returns a struct to the caller.
Since the tag does not output anything, I used <cfsilent> around the entire thing. Well, as a result, that wiped out all of the rendered content of the calling template.
"No problem," I thought. "I'll just use <cfsetting enablecfouputonly='yes' /> to take care of it."
Lo and behold, I had rendered content! Well, I had *some* of it. However, naturally, I did not have any rendered content that was not inside of <cfoutput> tags.
As you probably already know, ColdFusion custom tags have their own little space in memory for their variables scope. Because of this, I assumed that the aforementioned tags would not affect the output of the calling template. Obviously I assumed incorrectly.
So my question is two-fold:
1. Why do these tags have an affect on the calling template? I mean, content processed before and after these tags is still wiped out by their use. That kinda befuddles me. (Not that that's a particularly difficult thing to do.)
2. Now that I know this, what options do I have for suppressing that extra whitespace? Or does the custom tag not even cause additional whitespace?
If you have the answers, or can point me in the right direction for the answers, I'd most certainly appreciate it.
If on the other hand you're using these tags and trying to figure out why nothing is being rendered, well, now you know the answer to "what" portion of your question, and you can wonder along with me about the "why" portion. :-)
Latest Articles
- No recent entries.
Categories
- ColdBox (21) [RSS]
- ColdFusion (92) [RSS]
- Fusebox (3) [RSS]
- General (22) [RSS]
- jQuery (15) [RSS]
- Kalendar (1) [RSS]
- Linux (1) [RSS]
- Mura CMS (1) [RSS]
- Railo (1) [RSS]
- Rants (5) [RSS]
- Transfer (8) [RSS]
- Uni-Form Tag Library (36) [RSS]



There are no comments for this entry.
[Add Comment]