# CFMODULE

Use CFMODULE to invoke a custom tag for use in your ColdFusion application pages. CFMODULE can help deal with any custom tag name conflicts that might arise.

Use the TEMPLATE attribute to name a ColdFusion page containing the custom tag definition, including its path. Use the NAME attribute to refer to the custom tag using a dot notation scheme indicating the location of the custom tag in the ColdFusion installation directory.

### Syntax

    <CFMODULE TEMPLATE="template"
        NAME="tag_name"
        ATTRIBUTECOLLECTION="collection_structure"
        ATTRIBUTE_NAME1="value"
        ATTRIBUTE_NAME2="value"
        ...>

#### TEMPLATE

Used in place of NAME, defines a path to the application page (.cfm file) implementing the tag. Relative paths are expanded from the current page. Physical paths are not allowed. Absolute paths are expanded using the ColdFusion mappings.

#### NAME

Used in place of TEMPLATE, defines the name of the custom tag in the form "Name.Name.Name... " that uniquely identifies a subdirectory containing the custom tag page under the root directory for CF custom tags. For example:

    <CFMODULE NAME="Allaire.Forums40.GetUserOptions">

Identifies the page `GetUserOptions.cfm` in the directory `CustomTags\Allaire\Forums40` under the root directory of the ColdFusion installation.

#### ATTRIBUTECOLLECTION

Optional. A structure that contains a collection of key-value pairs that represent attribute names and their values. You can specify as many key-value pairs as needed. However, you can specify the ATTRIBUTECOLLECTION attribute only once. See Usage for more information.

#### ATTRIBUTE_NAME

Optional. Attributes you want your custom tag to use. You can use as many attributes as needed to specify the parameters of a custom tag. Each

### Usage

You can use ATTRIBUTECOLLECTION and ATTRIBUTE in the same call.

Within the custom tag code, the attributes passed with ATTRIBUTECOLLECTION are saved as independent attribute values with no indication that the attributes were grouped into a structure by the custom tag's caller.

Likewise, if the custom tag uses a CFASSOCIATE tag to save its attributes, the attributes passed with ATTRIBUTECOLLECTION are saved as independent attribute values with no indication that the attributes are grouped into a structure by the custom tag's caller.

### Example

    <!--- This example shows the use of CFMODULE --->
    <HTML>
    <HEAD>
    <TITLE>CFMODULE Example</TITLE>
    </HEAD>

    <BODY>
    <H3>CFMODULE Example</H3>

    <P>
    This example shows the use of CFMODULE to call a sample custom
    tag inline.
    </P>
    <P>
    This example makes use of a sample custom tag that has been saved in the
    file myTag.cfm in the snippets directory. You can also save ColdFusion
    custom tags in the Cfusion\CustomTags directory. For more information
    about using Custom Tags, please refer to
    <i>Developing Web Applications</i>.
    </P>
    <!--- show the code in the custom tag--->
    <P>Here is the code in the custom tag.</P>
    <CFOUTPUT>#HTMLCodeFormat("<CFSET X = attributes.x>
    <CFSET Y = attributes.y>
    <CFSET A = attributes.value1>
    <CFSET B = attributes.value2>
    <CFSET C = attributes.value3>
    <CFSET caller.result = x + y + a + b + c>")#
    </CFOUTPUT>
    <!--- end sample tag --->

    <CFSET attrCollection1 = StructNew()>
    <CFSET attrCollection1.value1 = 22>
    <CFSET attrCollection1.value2 = 45>
    <CFSET attrCollection1.value3 = 88>

    <!--- Call the tag with CFMODULE with Name--->
    <CFMODULE
       Template="..\snippets\myTag.cfm"
        X="3"
        attributeCollection=#attrCollection1#
        Y="4">

    <!--- show the code --->
    <P>Here is one way in which to invoke the custom tag,
    using the TEMPLATE attribute.</P>
    <CFOUTPUT>#HTMLCodeFormat(    "<CFMODULE
        Template=""..\snippets\myTag.cfm""
        X=3
        attributeCollection=##attrCollection1##
        Y=4>")#
    </CFOUTPUT>
    <P>The result: <CFOUTPUT>#result#</CFOUTPUT> </P>

    <!--- Call the tag with CFMODULE with Name--->
    <CFMODULE
        NAME="myTag"
        X="3"
        attributeCollection=#attrCollection1#
        Y="4">

    <!--- show the code --->
    <P>Here is another way to invoke the custom tag,
    using the NAME attribute.</P>
    <CFOUTPUT>#HTMLCodeFormat(    "<CFMODULE
        NAME='myTag'
        X=3
        attributeCollection=##attrCollection1##
        Y=4>")#
    </CFOUTPUT>
    <P>The result: <CFOUTPUT>#result#</CFOUTPUT>

    <!--- Call the tag using the short cut notation --->
    <CF_myTag
        X="3"
        attributeCollection=#attrCollection1#
        Y="4">

    <!--- show the code --->
    <P>Here is the short cut to invoking the same tag.</P>
    <CFOUTPUT>#HTMLCodeFormat(    "<CF_myTag
        X=3
        attributeCollection=##attrCollection1##
        Y=4>")#
    </CFOUTPUT>
    <P>The result: <CFOUTPUT>#result#</CFOUTPUT></P>

    </BODY>
    </HTML>