Stealing Functionality From PHP: include_once()
Chances are that if you're a ColdFusion developer, you've at least looked at some PHP code every now and then. Even if just to see how much better our language of choice is than theirs. ;)
Something that I always thought was cleverly done in PHP was include_once(). If you're not familiar with it, basically it's the same thing as <cfinclude>, except that if the requested file has already been included for the current request, the command is ignored. I've written a custom tag that will accomplish the same thing for you. Click through for the code!
[viewcode] src="includeOnce.cfm.txt" showsyntax=no link=yes geshi=cfm[/viewcode]
Using listContainsNoCase() means that you can include templates using either Upper Case or lower case for the template name (on Windows) and unlike PHP, it will still only be included once. Note that on Linux file names are case sensitive, so this doesn't apply. If you use Linux and (cringe) files with the same name but different case, then you'll want to remove the NoCase part.
Posted in ColdFusion