Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GetBaseTagData() Works Differently In Adobe ColdFusion 2018 And Lucee CFML 5.3.7.47
<cfimport prefix="my" taglib="./" />
<!--- Three nested DIV tags. --->
<my:Div id="div:outer">
<my:Div id="div:middle">
<my:Div id="div:inner">
<!--- Three nested SECTION tags. --->
<my:Section id="section:outer">
<my:Section id="section:middle">
<my:Section id="section:inner">
<!--- Runtime-specific traversal tag. --->
<cfif server.keyExists( "Lucee" )>
<cf_InspectTagsLucee />
<cfelse>
<cf_InspectTagsACF />
</cfif>
</my:Section>
</my:Section>
</my:Section>
</my:Div>
</my:Div>
</my:Div>
<cfscript>
writeOutput( "<h1> Adobe ColdFusion </h1>" );
tagNames = getBaseTagList().listToArray();
// In Adobe ColdFusion, the second getBaseTagData() argument tells the runtime which
// INSTANCE of a tag to return. As such, since we have multiple tags with the same
// name, we have to keep track of how many times we've seen with a given name so that
// we can skip over those instances.
instanceCounters = {};
for ( tagName in tagNames ) {
// If we haven't seen a tag with this name yet, default to zero so that we can
// start incrementing the visitations.
if ( ! instanceCounters.keyExists( tagName ) ) {
instanceCounters[ tagName ] = 0;
}
// Increment the instance counter for this tag so that we either get the first
// instance (or the "next" instance if we have a non-zero index).
tagData = getBaseTagData( tagName, ++instanceCounters[ tagName ] );
id = ( tagData.attributes.id ?: "none" );
writeOutput( "&bull; #tagName# &mdash; ID: #id# <br />" );
}
cfexit( method = "exitTag" );
</cfscript>
<cfscript>
echo( "<h1> Lucee </h1>" );
loop
index = "i"
value = "tagName"
array = getBaseTagList().listToArray()
{
// In Lucee CFML, the second getBaseTagData() argument tells the runtime how many
// tags to SKIP OVER as it traverses the hierarchy looking for a matching name.
// As such, since we have multiple tags with the same name, we have to skip over
// tags we've already visited in order to get to the right tag.
// --
// NOTE: We are using -1 here because we don't want to skip the CURRENT tag when
// traversing the tag hierarchy. The current tag will be the first tag listed in
// the getBaseTagList() return.
tagData = getBaseTagData( tagName, ( i - 1 ) );
id = ( tagData.attributes.id ?: "none" );
echo( "&bull; #tagName# &mdash; ID: #id# <br />" );
}
exit method = "exitTag";
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment