Skip to main content
Participant
April 3, 2006
Answered

customtag adds spaces?

  • April 3, 2006
  • 4 replies
  • 412 views
I have a customtag that outputs a string, but i've noticed that spaces are added at the start and end of that string. These spaces are not in the customtag, the string has been trimmed!

So why does the customtag add spaces? and how do i prevent that? (i know i can return the string in a variable to the caller page and then output that on the caller page, that works fine, but i don't want it like that).
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
This is a known issue with coldfusion's whitespace handling. enablecfoutputonly does not ignore carriage returns and whitespace. You can turn on whitespace management in the ColdFusion administrator. You can/should also use <cfsilent> copiously. If you have a tag where leading/trailing whitespace is absolutely critical, the approach I've used is to build up a string for later display in the tag, e.g.

4 replies

droopcatAuthor
Participant
April 18, 2006
Thanks! Works fine since i use <cfsilent>
Participating Frequently
April 3, 2006
If you format your custom tag with tabs or leading spaces, these can get included when the custom tag displays. You will probably want to control everything with the <cfsetting enablecfoutputonly="Yes"> tag and <cfoutput> tags around your display.

Even though you don't want to, you get a lot more control over returning the value of the string, and then displaying it. That's why it is often recommended.
droopcatAuthor
Participant
April 7, 2006
I have added a <cfprocessingdirective suppresswhitespace="yes"> around all the code in the customtag, but i still get a leading and trailing space, the enablecfoutputonly is also in place and i am outputting the string i want trimmed and all between <cfoutput>'s.

I have found something that solves this problem, but it makes no sense at all!

That is, if i put all the CFML tags on one line of code, instead of using a nicely readable markup, it doesn't output the spaces!!! But what has the placement of my serverside tags to do with this. It shouldn't matter at all! especially not when i'm already using supresswhitespace!

Any ideas?
Correct answer
April 7, 2006
This is a known issue with coldfusion's whitespace handling. enablecfoutputonly does not ignore carriage returns and whitespace. You can turn on whitespace management in the ColdFusion administrator. You can/should also use <cfsilent> copiously. If you have a tag where leading/trailing whitespace is absolutely critical, the approach I've used is to build up a string for later display in the tag, e.g.