Skip to main content
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes and Ezra Parker and Dan Wilson and John Mason and Jason Dean and Luis Majano and Mark Mandel and Brian Kotek and Wil Genovese and Rob Brooks-Bilson and Andy Matthews and Simeon Bateman and Ray Camden and Chris Rockett and Joe Bernard and Dan Skaggs and Byron Raines and Barney Boisvert and Simon Free and Steve 'Cutter' Blades and Seth Bienek and Katie Bienek and Jeff Coughlin
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes Ezra Parker Dan Wilson John Mason Jason Dean Luis Majano Mark Mandel Brian Kotek Wil Genovese Rob Brooks-Bilson Andy Matthews Simeon Bateman Ray Camden Chris Rockett Joe Bernard Dan Skaggs Byron Raines Barney Boisvert Simon Free Steve 'Cutter' Blades Seth Bienek Katie Bienek Jeff Coughlin

CFSaveContent Trim And Append Attributes In Lucee CFML 5.3.7.47

By
Published in Comments (2)

The other day on the Lucee Dev forum, I proposed that we add a file attribute to the CFSaveContent tag in Lucee CFML. And, as I was writing that proposal, I pulled up the docs page for the CFSaveContent tag; which is when I was surprised to see that Lucee actually offers two additional attributes on that tag: trim and append. I had no idea that these existed. So, I wanted to put together a quick demo (for myself) in Lucee CFML 5.3.7.47.

The names of these two attributes are mostly self-explanatory: trim will remove the leading / trailing whitespace of the generated content; and, append will add the content to an existing variable rather than just overwriting it. In the following demo, you'll see that I have 4 CFSaveContent instances, but they are all writing to the same variable:

<!---
	In Lucee CFML, the CFSaveContent tag offers two additional attributes:

	* trim - removes leading / trailing whitespace.
	* append - adds the content to an existing variable.
--->
<cfsavecontent variable="data" trim="true">
	Roses are red,
</cfsavecontent>

<cfsavecontent variable="data" trim="true" append="true">
	Violets are blue,
</cfsavecontent>

<cfsavecontent variable="data" trim="true" append="true">
	Lucee is insanely powerful,
</cfsavecontent>

<cfsavecontent variable="data" trim="true" append="true">
	Deal with it!
</cfsavecontent>


<cfset comma = "," />
<cfset commaWithLinebreak = ",#chr( 10 )#" />

<cfoutput>
	<pre>#data.replace( comma, commaWithLinebreak, "all" )#</pre>
</cfoutput>

All of the CFSaveContent tags are appending values to the data variable. And so, when I go to output the data variable at the end, we get this:

The output of CFSaveContent with trim and append in Lucee CFML.

I think this could be pretty cool. I'm almost certain that I've wanted something to this effect in the past. I'm loving discovering these tiny little hidden gems in Lucee CFML.

Want to use code from this post? Check out the license.

Reader Comments

294 Comments

Yet another fine example where Lucee shines over ACF, which does not support these attributes. (sad trombone 🎵)

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed hosting services provided by:
xByte Cloud Logo