Skip to main content
November 24, 2015
Question

When will we be able to use cfmodule from inside of cfscript?

  • November 24, 2015
  • 2 replies
  • 1225 views

Is something like this planned as an update? When?

Currently we have to write really ugly code (script and tag code mixed) to get some legacy module files loaded into our components. I'm not talking about few files here, we have been using CF since version 5 and refactoring everything isn't an option.

Only workaround seems to create the ModuleTag java object in the coldfusion.tagext.lang package and call out the module that way. This is really hacky though since cfusion.jar can have class updates. Or perhaps there are some better solutions?

    This topic has been closed for replies.

    2 replies

    November 25, 2015

    <!---   

    Variables = new module(template="/cfm/filepath/file.cfm", {arg1="a", arg2="b"}, Variables)

    --->

    <cfcomponent>

    <cffunction name="init" output="True" access="Public" returnType="Any">

        <cfargument name="template" type="String" required="True">

        <cfargument name="moduleArguments" default="#StructNew()#">

        <cfargument name="superVariables" default="#StructNew()#">

        <cfmodule template="#Arguments.template#" attributecollection="#Arguments.moduleArguments#" />

        <cfset StructDelete(Variables, "init")>

        <cfset StructDelete(Variables, "this")>

        <cfreturn StructAppend(Arguments.superVariables, Variables)>

    </cffunction>

    </cfcomponent>

    // Variables = new module("/path/file.cfm", {arg1="", arg2=""}, Variables);

    This is the wrapper I've been working on so far.

    WolfShade
    Legend
    November 24, 2015

    According to a blog by Adam Cameron from 2014, you _can_ use CFMODULE in CFSCRIPT - it's just module(arg,arg), not cfmodule(arg,arg).

    HTH,

    ^_^

    November 25, 2015

    That might be the case with Railo server which we don't use.

    Both cfmodule & module methods give undefined variable error.

    We are running CF10

    Carl Von Stetten
    Legend
    November 27, 2015

    That's because the cfmodule script equivalent of <cfmodule> wasn't added until CF11.

    -Carl V.