January 5, 2024
Dealing with Deprecated tags
Comments
(2)
January 5, 2024
Dealing with Deprecated tags
Good ol' ColdFusion developer that has 20 years of experience with the language 
Master 7 posts
Followers: 2 people
(2)

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">
<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">

Menuitem.cfm:
<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 CFMENITEM 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.

2 Comments
2024-02-01 03:44:16
2024-02-01 03:44:16

Nice job, Igor.

But I happened to notice that the code had stylized quotes that made it fail if we copy/pasted it out of the article to run it, so I have edited the post just to format the code to fix that problem. (Adobe has allowed me to have that edit privilege, and I RARELY use it but it made sense in this situation.)

You may notice it also now uses the HTML <code> tag so that the code stands out from the rest of the text. Sadly, I couldn’t get the blog editor to allow me to indent the code (even when I told it to use &nbsp; for spaces, it removed them). But at least the first problem is solved.

Hope more people can benefit from your helpful custom tags here.

Like
(1)
>
Charlie Arehart
's comment
2024-02-01 14:12:41
2024-02-01 14:12:41
>
Charlie Arehart
's comment

Thank you

Like
Add Comment