ColdFusion Zeus POTW: CFINCLUDE Improvement

Welcome to the first ColdFusion Zeus POTW (Preview of the Week). This is a new blog series where I’ll be highlighting one feature a week from the upcoming new version of ColdFusion code-named Zeus. As with any preview, you should remember that things may, and probably will, change a bit before the final product is released. That being said, this is your early opportunity to voice your opinion. Some POTWs will be deep dives into large topics. Some, like today, will be simple, small changes that are meant to improve your day to day coding life. What I’m about to show is really small. But it’s one of those nice things that I think you will really appreciate.

Any one who has made use of cfinclude in the past has probably run into situations where they’ve accidentally included the same template twice. Some times this isn’t a big deal. Other times it can lead to bugs or just having your site run a bit slower than expected.

ColdFusion Zeus adds a simple way to ensure your includes are never run more than once. Consider the template below:

<cfinclude template="include_target.cfm" runonce="true"> <cfinclude template="include_target.cfm" runonce="true">

We’ve added a new attribute, runonce, that when set to true, will ensure the target of the include is only executed once. This is request-level intelligent as well. So given this CFM:

<cfinclude template="include_target.cfm" runonce="true">

<cfinclude template=”include_test.cfm”> </code>

If include_test.cfm contains the include statements you saw above, then they recognize that they were already run before in the parent. Hopefully that didn’t come out as confusing as it sounds. ;)

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments