/
2009-05-26-coldfusion-whitespace.html
46 lines (37 loc) · 1.33 KB
/
2009-05-26-coldfusion-whitespace.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
title: ColdFusion whitespace
tags:
---
<p>
Quick hit today. Somehow I went six years working with ColdFusion without knowing that functions implicitly output anything inside them, including whitespace! For example, say you have the following function in english.cfc:
</p>
<pre name="code" class="html">
<CFFUNCTION name="getHint">
<CFRETURN "Available only in Professional Edition.">
</CFFUNCTION>
</pre>
<p>
And you call it from a template like so:
</p>
<pre name="code" class="html">
<cfobject component="english" name="localise">
<input type="Button" title="#localise.getHint()#">
</pre>
<p>
The actual out will be:
</p>
<pre name="code" class="html">
<input type="Button" title="
Available only in Professional Edition.">
</pre>
<p>
See, it's rendering the whitespace from inside the function, ie the linebreak after <CFFUNCTION> and the tab before <CFRETURN>. It only gets worse as the function gets longer. What you need to do is pass the attribute output="false" to the CFFUNCTION definition.
</p>
<pre name="code" class="html">
<CFFUNCTION name="getHint" output="false">
<CFRETURN "Available only in Professional Edition.">
</CFFUNCTION>
</pre>
<p>
Now, I just need to find out how to make that the default...
</p>