Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 01:00
Show Gist options
  • Save bennadel/9753268 to your computer and use it in GitHub Desktop.
Save bennadel/9753268 to your computer and use it in GitHub Desktop.
I Wish: ColdFusion Custom Tag Query Looping
<cfswitch expression="#THISTAG.ExecutionMode#">
<cfcase value="Start">
<!--- Param the query name. --->
<cfparam
name="ATTRIBUTES.Query"
type="variablename"
/>
<!--- Default the loop index. --->
<cfset VARIABLES.LoopIndex = 1 />
</cfcase>
<cfcase value="End">
<!--- Check to see if loop index is not too high. --->
<cfif (VARIABLES.LoopIndex LT CALLER[ ATTRIBUTES.Query ].RecordCount)>
<!--- Increment the index. --->
<cfset VARIABLES.LoopIndex++ />
<!--- Loop over *only* the selected row. --->
<cfloop
query="CALLER.#ATTRIBUTES.Query#"
startrow="#VARIABLES.LoopIndex#"
endrow="#VARIABLES.LoopIndex#">
<!--- Run the body of the tag again. --->
<cfexit method="loop" />
</cfloop>
</cfif>
</cfcase>
</cfswitch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment