Skip to main content
Inspiring
October 10, 2012
Answered

CF10 cannot find my Custom Tag. CFParam WILL have a Hint!

  • October 10, 2012
  • 3 replies
  • 7247 views

It is a travesty beyond travesty that the cfparam tag does not support a 'hint' attribute.   So I aims to fix that with a custom tag!  This is the first time I've messed with custom tags, but so far I cannot get them to work.

I created a file called param.cfm, it merely outputs a cfparam that transposes the provided ATTRIBUTES but allows us to specify a hint attribute on the <cf_param> tag to sate that need.

I placed this file into c:\inetpub\wwwroot\project\custom-tags.

In my application.cfc, it states simply:

<cfset THIS.name = hash( getCurrentTemplatePath() )>

<cfset THIS.customTagPaths = 'c:|inetpub\wwwroot\project\custom-tags'>

<cf_param name="test" type="string" default="foo" hint="YES! WE CAN PUT HINTS ON PARAMS!">

<cfabort>

Well, CF comes back and says:

Expression Exception - in c:/inetpub/wwwroot/project/application.cfc: line 17

Cannot find CFML template for custom tag param.

I did some research and saw that there are supposed to be 4 locations CF will look for custom tags:

  • In the same directory as the calling page
  • In the directory specified on a per-application basis
  • In the ColdFusion CustomTags folder or a subdirectory of it
  • In a directory defined in the ColdFusion ACP

Well, I have per-application settings enabled in the CF ACP, and I have both named and defined the custom tags path for this application, yet CF still cannot find it.  So what am I doing wrong here?

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Sorry, I was not clear.

    The customTagsPath thing doesn't work for custom tag calls from the pseudoconstructor.  It works fine everywhere else.

    This doesn't really surprise me now that I think about it.

    CF is basically doing this, under the hood:

    appSettingAndHandlers = new Application()
    
    theApp.setName(appSettingAndHandlers.name)
    theApp.setCustomTagPaths(appSettingAndHandlers.customTagPaths)
    //etc
    
    if not theApp.started() then
         theApp.start()
         appSettingAndHandlers.onApplicationStart()
    
    // etc
    

    So whilst it gathers the settings from the pseudo constructor of Application.cfc, just because there's a line of code declaring the setting's value doesn't mean the value has been applied to anything yet.

    Bear in mind Application.cfc is just a normal CFC, and the act of doing this:

    this.customTagPaths = "stuff here";

    merely sets a variable.  Setting that variable does not magically make the variable mean something, or execute any other code.

    Heh.  That's quite interesting.  I never thought of any of this stuff before.

    --

    Adam

    3 replies

    Inspiring
    October 10, 2012

    I have verified that this simply doesn't work (on any version of CF that supports the customTagPaths setting in Application.cfc).

    I cannot see anywhere that it's stated that this is by design, or what.  If it's by design, I'd call it a bit shonky.

    It also does not work in Railo.

    That said, I'm with Jason: if you need to put comments by your <cfparam> tags, then just put comments.  Creating a custom tag just so you can embed a comment in it is... um... a bit misguided, IMO.  Comments are not supposed to be part of your executable code, and to write your code in such a way as they are part of your execute code is simply wrong-headed.  Sorry.

    --

    Adam

    Inspiring
    October 10, 2012

    Well, if I understand correctly, the first time a page is rendered, it compiles to code that omits all comment processing.

    Even if I don't "extend" the <cfparam> tag with this attribute, I can see the value in custom tags, however if they don't work properly, it kind of harkens back to a bigger problem.  I can resolve to just comment out my params for the time being, but I'm a bit stubborn with this custom tag problem.

    I cross checked Nadel, Forta and Camden's sites and couldn't find anything regarding a discovery that customTagPaths was broken/ignored.  Just seems like a hard pill to swallow for such a glaring issue.

    I really don't want to put my custom tags into the CF server, because I won't have access to doing this on my host.  Putting them in the same directory hierarchy would just gnaw at my over zealous nature to keep my directories clean and organized....

    Adam Cameron.Correct answer
    Inspiring
    October 10, 2012

    Sorry, I was not clear.

    The customTagsPath thing doesn't work for custom tag calls from the pseudoconstructor.  It works fine everywhere else.

    This doesn't really surprise me now that I think about it.

    CF is basically doing this, under the hood:

    appSettingAndHandlers = new Application()
    
    theApp.setName(appSettingAndHandlers.name)
    theApp.setCustomTagPaths(appSettingAndHandlers.customTagPaths)
    //etc
    
    if not theApp.started() then
         theApp.start()
         appSettingAndHandlers.onApplicationStart()
    
    // etc
    

    So whilst it gathers the settings from the pseudo constructor of Application.cfc, just because there's a line of code declaring the setting's value doesn't mean the value has been applied to anything yet.

    Bear in mind Application.cfc is just a normal CFC, and the act of doing this:

    this.customTagPaths = "stuff here";

    merely sets a variable.  Setting that variable does not magically make the variable mean something, or execute any other code.

    Heh.  That's quite interesting.  I never thought of any of this stuff before.

    --

    Adam

    12Robots
    Participating Frequently
    October 10, 2012

    I'm sorry, I don't really have an answer for you except for routine stuff.  Does CF have read/execute permission to that directory? Have you tried dropping the cfm into the CF custom_tags server directory?

    I am curious though, why do you think (so strongly) that cfparam needs a hint attribute? What purpose would it server?

    Jason

    Inspiring
    October 10, 2012

    Hey 12Robots.

    I placed the param.cfm into c:\coldfusion-10\cfusion\CustomTags and CF could not find the tag.

    As for the HINT attribute, I just love the thing.  I am a stickler for comments, and I hate having to provide a comment line for each param I create (and I param about EVERY variable that I will use)  It's just a cleaner implementation if I can provide the hint inline with the param declaration.  I was being a bit facetious with saying it was adamant, but I'd love to extend cfparam to support it, and this seems like the next best thing.

    Also, how would I determine (without providing simple file read/writes) that CF has read/write rights to a specified folder?  Is there a NTFS account that is supposed to be on it?  What account does CF use to determine those rights?

    12Robots
    Participating Frequently
    October 10, 2012

    I would guess that, for whatever reason, those paths are not yet ready at that point in the application (you're trying this from App.cfc, right)?  I would bet that if you tried it from a cfm that they would work.

    Hints are not really there for commenting though. They exist for creating API documentation. Since cfparams cannot really be a part of an API, it doesn't really make sense for them to have hint attributes.

    Jason

    Inspiring
    October 10, 2012

    Just a FYI, I tried putting this tag in the same directory as application.cfc and boom, it found it.  So the problem cannot be related to this code running outside methods in the application.cfc.  It simply is ignoring the THIS.customTagPaths value that was provided.

    Inspiring
    October 10, 2012

    Also, the forum editor is very screwy.  For 'protection' reasons, probably, it changed my custom tag path to use a pipe ( | ), but the path is correct.  I cut and paste it into the run prompt and up came the directory with my custom tag in it.  I also provided EVERY application variable before aborting just to make sure things were configured up the wazoo (technical term).  I've even restarted the Application Server service.  Someone suggested that "once CF finds a CF tag (or doesn't), it caches that result until a service/server restart.