Question

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.

Was it helpful?

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.

OTHER TIPS

Contrary to what Jayson reported - I have CFIMPORT working just fine w/ a per application mapping vs one globally set in CFAdmin. CFIMPORT is pretty cranky about mappings (for instance you cannot use variable for relativepath, nor use expandpath) - but you should be able to do what you are requesting w/o issue.

Do you have "Enable Per App Settings" checked in CFAdmin | Settings to allow you the use of this.mappings? What version of CF are you running? I'm using CF8 with this code and have no issues:

Application CFC (outside a function but w/in component):

this.rootPath = getDirectoryFromPath(getCurrentTemplatePath());  // this assures path of application.cfc is used to determine path, likely equivalent to expandPath("/")
structInsert(this.mappings, '/vp', this.rootPath);

In CFC (outside a function but w/in component):

<cfimport prefix="loader" taglib="/vp/view/_loader/">

I can then use in the CFC and it works as expected.

I'm pretty sure you can't do anything fancy with the cfimport tag. I think you have to use relative paths, and you have to include it manually on every page. (vs. putting it in the application.cfc file somewhere or whatever)

I'm pretty sure that expandPath respects CF mappings. Have you tried something like this?

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

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

I've confirmed it... you cannot use mappings that are created via the "this.mappings" structure in the application.cfc.

From Adobe's documentation (Coldfusion 9):

The path must be relative to the web root (and start with /), the current page location, or a directory specified in the Administrator ColdFusion mappings page.

CFImport Documentation for CF 9

Not sure why application.cfc mappings work for just about everything else but this. Kind of disappointing, since I've loved the idea of defining as little as possible in the Administrator. I like just zipping up an application and deploying it anywhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top