coldfusioncfimport

Custom Tags and cfimport


Do Custom Tags work with mappings? I'm trying not to have to address the CustomTags folder as a relative address.

I've tried:

<cfset this.mappings["/CT"] = Expandpath("/myProjects/Project1/CustomTags")>

inside of Application.cfc and then

<cfimport prefix="tag" taglib="/CT">

inside of my page, but it doesn't.

It says:

Cannot import the tag library specified by /CT. The following error was encountered: C:\Inetpub\wwwroot\CT. Ensure that you have specified a valid tag library.


Solution

  • The docs says it works with a directory specified in the Administrator ColdFusion mappings page. Have you tried setting the mapping in the ColdFusion administrator to see if that works first? If that works, but the this.mappings set per application in the application.cfc doesn't work, then possibly it is a bug?!?

    EDIT: I tested Adam's suggestion to use the expandPath() function, but this also does not work because the taglib attribute must contain a constant value. It cannot contain a variable or function. It simply doesn't work unless you use a mapping set in the ColdFusion Administrator. I tried the following tests using this application.cfc.

    <cfcomponent>
    
        <cfset this.name = "TestApp" />
        <cfset this.loginStorage = "session" />
        <cfset this.sessionManagement = true />
        <cfset this.setClientCookies = true />
        <cfset this.setDomainCookies = false />
        <cfset this.sessionTimeOut = CreateTimeSpan(0,12,0,0) />
        <cfset this.applicationTimeOut = CreateTimeSpan(1,0,0,0) />
        <cfset this.mappings['/CT'] = "C:\apache\htdocs\myProjects\Project1\CustomTags"/>
    
    </cfcomponent>
    

    And this in a ColdFusion template:

    <cfimport prefix="tag" taglib="#expandpath('/CT')#">
    

    Throws the error:

    This expression must have a constant value.

    <cfset CT = expandpath('/CT')/>
    <cfimport prefix="tag" taglib="#CT#">
    

    Throws the error:

    This expression must have a constant value.