Suppressing whitespace and saving content with cfscript

Posted on Monday, October 11th, 2010 at 7:56 pm

I was writing a while back some script based components. In one function I needed to save some HTML content into a variable and I needed to make sure that the whitespace was controlled. In tag-based CF it would look something like the following.

<cfprocessingdirective suppresswhitespace="true">
	<cfoutput>
		<cfsavecontent variable="loc_data">
			<div>
				<p>
					This is some HTML content!
				</p>
			</div>
		</cfsavecontent>
	</cfoutput>
</cfprocessingdirective>

When I went to look up the documentation on how to write the equivalent of this in script the relevant bits and pieces were few and far between. So I ended up just trying some different ways of writing it that made sense and sure enough the processingdirective tag does have a script equivalent. The script version of this will look like the following. It’s actually much simpler and cleaner if you ask my opinion.

processingdirective suppresswhitespace=true
{
	savecontent variable="this_data"
	{
		writeOutput('<div><p>This is some HTML content!</p></div>');
	}
}

So in the end pretty simple. The documentation just isn’t very user friendly on the cfscript end. Hopefully this will get better as it is a cleaner way to write components.

Tags
CategoryColdfusion

Leave a Reply

*
(Won't be published) *