Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active October 6, 2025 23:13
Show Gist options
  • Save JamoCA/e231a426337fcb83cd4ad5ab16a97fa6 to your computer and use it in GitHub Desktop.
Save JamoCA/e231a426337fcb83cd4ad5ab16a97fa6 to your computer and use it in GitHub Desktop.
Proof-of-concept CFML to contrast and compare CFModule / CFTag Execution Mode Behavior
<!--- 2025-10-06 15:22:49-07
In response to LinkedIn question from Ben Nadel:
https://www.linkedin.com/feed/update/urn:li:activity:7381052444270567425/
NOTE: All executions using "cftag (cfscript)" result in both start/end executions being triggered.
FIX: To avoid being double executed in cfscript, we modify the cftag/cfmodule to exit early if `thisTag.executionMode=end`
on implmentations that don't make use of `thisTag.GeneratedContent`.
--->
<cfparam name="url.TestType" default="cfml">
<cfparam name="request.moduleOrder" default="#arraynew(1)#">
<!--- executed as cfmodule or cftag? --->
<cfif isdefined("thisTag.executionMode")>
<cfparam name="attributes.name" default="default">
<cfset arrayappend(request.moduleOrder, attributes.name & "-" & thisTag.executionMode)>
<cfset hasEnd = (thisTag.HasEndTag) ? "has-end-Tag" : "no-end-tag">
<cfset title = arraytolist([attributes.name, url.TestType, thisTag.executionMode, hasEnd], " / ")>
<cfoutput>
<h2>Module #title#</h2>
<div>#arraytolist(request.moduleOrder, " | ")#</div>
</cfoutput>
<cfif thisTag.executionMode eq "end">
<cfoutput>
<fieldset><legend>END: #title#</legend>
<cfoutput><div>#encodeforhtml(trim(thisTag.GeneratedContent))#</div></cfoutput>
</fieldset>
</cfoutput>
<cfelseif !thisTag.HasEndTag>
<cfoutput>
<fieldset><legend>NO END: #title#</legend>
<div>#encodeforhtml(trim(thisTag.GeneratedContent))#</div>
</fieldset>
</cfoutput>
</cfif>
</cfif>
<cfif !isdefined("thisTag.executionMode")>
<style>
a {background-color:#f44336; color:white; padding:14px 25px; text-align:center; text-decoration:none; display:inline-block;}
a:hover, a:active, a.on {background-color: black;}
</style>
<cfoutput>
<h1>CFModule / CFTag Execution Mode Behavior (Mode: #url.TestType#)</h1>
</cfoutput>
<div>
<a href="?testType=cfml"<cfif url.TestType eq "cfml"> class="on"</cfif>>cfmodule (CFML)</a>
<a href="?testType=cfscript"<cfif url.TestType eq "cfscript"> class="on"</cfif>>cfmodule (cfscript)</a>
<a href="?testType=cftagcfml"<cfif url.TestType eq "cftagcfml"> class="on"</cfif>>cftag (CFML)</a>
<a href="?testType=cftagcfscript"<cfif url.TestType eq "cftagcfscript"> class="on"</cfif>>cftag (cfscript)</a>
</div>
<!--- cfmodule syntax --->
<cfif url.TestType eq "cfml">
<cfset args = ["name": "a"]>
<cfmodule template="moduleTest.cfm" attributecollection="#args#">
<cfset args = ["name": "b"]>
<cfmodule template="moduleTest.cfm" attributecollection="#args#">
<cfset args = ["name": "c"]>
<cfmodule template="moduleTest.cfm" attributecollection="#args#">
<cfoutput>#datetimeformat(now(),'iso')#</cfoutput>
</cfmodule>
<cfelseif url.TestType eq "cftagcfscript">
<cfscript>
args = ["name": "a"];
cf_moduleTest(attributecollection=args);
args = ["name": "b"];
cf_moduleTest(attributecollection=args);
args = ["name": "c"];
cf_moduleTest(attributecollection=args){
writeoutput(datetimeformat(now(),'iso'));
}
</cfscript>
<!--- cftag syntax --->
<cfelseif url.TestType eq "cftagcfml">
<cfset args = ["name": "a"]>
<cf_moduleTest attributecollection="#args#">
<cfset args = ["name": "b"]>
<cf_moduleTest attributecollection="#args#">
<cfset args = ["name": "c"]>
<cf_moduleTest attributecollection="#args#">
<cfoutput>#datetimeformat(now(),'iso')#</cfoutput>
</cf_moduleTest>
<cfelse>
<cfscript>
args = ["name": "a"];
cfmodule(template="moduleTest.cfm", attributecollection=args);
args = ["name": "b"];
cfmodule(template="moduleTest.cfm", attributecollection=args);
args = ["name": "c"];
cfmodule(template="moduleTest.cfm", attributecollection=args){
writeoutput(datetimeformat(now(),'iso'));
};
</cfscript>
</cfif>
<hr>
<h2>Post</h2>
<cfoutput>
<div>#arraytolist(request.moduleOrder, " | ")#</div>
</cfoutput>
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment