Dealing with Deprecated tags.
In my recent work on migrating older projects to ColdFusion 2023, I encountered the need to recreate the functionality of the deprecated CFMENU tag. Although I hadn’t used CFMENU before, adapting to the new environment prompted me to develop a solution using custom tags.I propose creating two custom tags to replicate the required functionality. Let’s refer to Adobe’s documentation for CFMENU as an example: https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfmenu.html
We need to create 2 Custom tags:
Menu.cfm: <cfsetting enablecfoutputonly=”Yes”><cfoutput>
<cfif (THISTAG.ExecutionMode EQ “Start”)><style>
ul##nav, ul##nav ul.subnav {padding:0; margin: 0; }
ul##nav li, ul##nav ul.subnav li {
list-style-type: none;display: inline-block;
}ul##nav li a, ul##nav li ul.subnav li a {
text-decoration: none;color: ##000;
background: <cfif isdefined(“Attributes.bgcolor”)>#Attributes.bgcolor#<cfelse>##ADD8E6</cfif>;padding: 5px;
display:inline-block;width: 150px;
font: helveticasize:<cfif isdefined(“Attributes.fontSize”)>#Attributes.fontSize#<cfelse>14px</cfif> }
ul##nav li {position: relative;
clear: both;}
ul##nav li ul.subnav {display:none;
position: absolute;left: 0;
width: 150px;background: ##ADD8E6; } ul##nav li:hover ul.subnav {
display:block;}
ul##nav li a:hover {color: ##000; } ul##nav li ul.subnav a:hover { color: ##000; }
</style><ul id=”nav”>
</cfif><cfif (THISTAG.ExecutionMode EQ “End”)>
</li></ul></cfif>
</cfoutput>
<cfsetting enablecfoutputonly=”No”><cfsetting enablecfoutputonly=”Yes”><cfparam name = “Caller.oldstatus” default = “false”>
<cfoutput><cfif (THISTAG.ExecutionMode EQ “Start”)>
<cfif findnocase(‘CF_MENUITEM,CF_MENUITEM’,GetBaseTagList()) and not Caller.oldstatus>
<cfset Caller.status = true><cfset Caller.oldstatus = true>
<cfelse><cfset Caller.status = false>
</cfif></cfif>
<cfif (THISTAG.ExecutionMode EQ “Start”)>
<cfif Caller.status><ul class=”subnav”>
</cfif><cfif not Caller.status and not Caller.oldstatus></li></cfif><li><a href=”<cfif isdefined(“Attributes.href”)>#Attributes.href#<cfelse>##</cfif>”> #Attributes.display#</a>
</cfif><cfif (THISTAG.ExecutionMode EQ “End”) and len(THISTAG.GeneratedContent)>
</ul></li></cfif>
</cfoutput><cfsetting enablecfoutputonly=”No”>
I utilized the Caller scope to manage nested CF_MENUITEM custom tags. With these two custom tags, you can seamlessly replace CFMENU with CF_MENU and CFMENUITEM with CF_MENUITEM as per the Adobe documentation example. While I haven’t incorporated all possible attributes, it’s straightforward to add any additional ones you may require.
If you have questions or need further assistance with this, feel free to reach out to me. I’m here to help.