I would like to call a custom tag using a variable in it's name. Like this
<cfset slist = 'product_categories'>
<cf_cu_show_#slist#>
This gives me an error on the #. The custom tag cu_show_product_categories is present and working when I call it the conventional way. The idea is to build a list to loop through, calling several custom tags.
<cfset slist = 'product_categories'>
<cfif a = 'blogs'>
<cfset slist = listAppend(slist,"blogs")>
</cfif>
<cfif b = 'posts'>
<cfset s_list = listAppend(slist,"last_posts")>
</cfif>
<cfloop list="#slist#" index="i">
<cf_cu_show_#i#>
</cfloop>
I tried to google, but cannot find anything useful. Any help would be appreciated.
As you already discovered, using a variable name in calling the custom tag is invalid. The way around this is to call the custom tag using the <cfmodule>
syntax instead. In your first scenario, you would call it like this.
<cfset slist = 'product_categories'>
<cfmodule template="cu_show_#slist#.cfm">
In the lower example, you would modify your code as such.
<cfset slist = 'product_categories'>
<cfif a = 'blogs'>
<cfset slist = listAppend(slist,"blogs")>
</cfif>
<cfif b = 'posts'>
<cfset s_list = listAppend(slist,"last_posts")>
</cfif>
<cfloop list="#slist#" index="i">
<cfmodule template="cu_show_#i#.cfm">
</cfloop>
Here's the documentation link on how to use <cfmodule>
.
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfmodule.html
I also found another decent link where they demonstrate your scenario in which you need to supply the tag name dynamically as seen here at https://flylib.com/books/en/2.375.1.420/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With