tags:

views:

471

answers:

5

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.

A: 

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)

Jason
This.mappings needs to be at the top of Application.cfc, and the cfimport needs to be on the page.I've successfully used This.mappings with cfinclude, but not cfimport.
cf_PhillipSenn
+1  A: 

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.

Jayson
A: 

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')#">
Adam Tuttle
A: 

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.

mujimu
It didn't work, but that's ok.I'll just reference my custom tags using relative addressing.The application.cfc stmts worked, but the cfimport failed.
cf_PhillipSenn
Make sure when using per-app mapping, that you do not have any global mappings in CFAdmin of the same name. In the case above, make sure you remove "/vp" from CFAdmin Mappings to assure CF uses the per-app one mapping vs the global.
mujimu
+1  A: 

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.

Steve G
Thanks for commenting Steve! Welcome to stackoverflow!
cf_PhillipSenn