4 Replies Latest reply on Apr 18, 2006 2:57 AM by droopcat

    customtag adds spaces?

    droopcat
      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).
        • 1. Re: customtag adds spaces?
          mike.short Level 1
          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.
          • 2. Re: customtag adds spaces?
            droopcat Level 1
            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?
            • 3. Re: customtag adds spaces?
              pmularien Level 1
              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. Re: customtag adds spaces?
                droopcat Level 1
                Thanks! Works fine since i use <cfsilent>