View Full Version : Leading space returned with function in ColdFusion

August 16th, 2009, 11:07 AM
I came across this issue while working on a customer's ColdFusion ecommerce site. The images were not displaying properly. The initial research showed that there was a space in front of the image name like:

/images/ Sample_thumb.jpg

That space of course does not allow the image to be displayed. The thumbnail image name was being returned from a function like:

<cffunction name="getThumbnail" access="public" returntype="string">
<cfargument name="filename" required="yes">
<cfset filename = arguments.filename>
<cfif filename neq "">
<cfset substr = find(".", filename)>
<cfset filename = left(filename, (substr-1))>
<cfset filename = Trim(filename & "_thumb.jpg")>
<cfreturn filename>

First, I did a CFOUTPUT right after the filename variable was set. This is when I noticed the space was already in the HTML source. After researching this further, I realized the function was creating the space, so to correct this, I needed to set the output="No" attribute of the function definition like:

<cffunction name="getThumbnail" access="public" returntype="string" output="No">

That solved the problem.