I'm not sure why I want this to work, but there's something about it that would just be neat. I think if this could be done, it would open up potentially interesting ways to loop over a ColdFusion query in custom ways that still feel very natural. I was trying to do something like this:
<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>
Handling the first row would obviously be difficult - I think it would have to be row 1. But, in the end of the tag, I'm trying to re-execute the ColdFusion custom tag body while in the context of the current query iteration (such that the calling page would think that it was actually in the #CurrentRow# of the query). This doesn't actually work as the moment you exit out of the custom tag, you lose the query context.
Anyway, not sure if anyone ever tried to do this or found a way to do it. Just having some fun on a Monday night, trying to think outside of the box.
Want to use code from this post? Check out the license.