Skip to main content
Ben Nadel
It's not enough; but, not enough is better than nothing.
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Kitt Hodsden
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Kitt Hodsden@kitt )

CFSaveContent Trim And Append Attributes In Lucee CFML

By Ben Nadel on
Tags: ColdFusion

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

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 variable="data" trim="true" append="true">
	Violets are blue,

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

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

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

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

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.

Reader Comments

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

Post A Comment

NEW: Some basic markdown formatting is now supported: bold, italic, blockquotes, lists, fenced code-blocks. Read more about markdown syntax »
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.