coldfusioncoldfusion-9

Can I call a custom tag in cfscript?


For example, if I have a custom tag like <cf_AppSwitch action="Check"> my assumption would be something like AppSwitch(action="Check"), but I am not certain CF can resolve that as a custom tag.

The other solution I can think of would be to write a wrapper function and call my custom tag, but that feels redundant.

It seems like I am oversimplifying a much more complex problem, so any insight would be appreciated (even as to why this is not/should not be supported).


Solution

  • Assuming you are using Adobe CF, unfortunately the answer is no. You have to write a wrapper function that is CFML-based. For example:

    <cffunction name="myCustomTag">
      <cfset var returnVal = "">
      <cfsavecontent variable="returnVal"><cf_myCustomTag attributeCollection=arguments></cfsavecontent>
      <cfreturn returnVal>
    </cffunction>
    
    <cfscript>
     myCustomTag(a="b");
    </cfscript>
    

    Now, if you are using Railo, you could use the cfscript equivalent to the <cfmodule> tag:

    <cfscript>
        module name="myCustomTag";
    </cfscript>