Always add the <cfimport> tag when using cfimport style syntax

Using cfimport is a great way to add custom tag functionality to your applications.

One thing you need to do of course is add a <cfimport> tag to every template where you want to use the cfimport syntax. However, a couple of times when I’ve been creating new templates I’ve forgotten this rule and not added <cfimport> and subsequently gotten confused when my results aren’t as expected.

I think the annoying thing is that ColdFusion does not throw an error in these situations, it just does nothing. So I can go to any template and add the following (without a <cfimport> on my template):

<tags:myNonExistentTag />

And the template runs without an error being thrown :(

So my reminder to myself before looking everywhere else is:

“Michael…for the love of Benji please check that you’ve added <cfimport> before doing any other debugging!”

Now my question (which I’m sure someone out there knows) is why does this not throw an error (missing template/include/tag etc)?

Post a Comment or Leave a Trackback

4 Comments

  1. March 3, 2008 at 5:21 am | Permalink

    Michael,
    My understanding is that ColdFusion does not throw an error here because without the CFIMPORT tag, the ColdFusion parser does not know to look for your tags. As far as CF is concerned, you have plain HTML and it gets passed through the CF engine and on to the browser as text. If you view source on the resulting output, you will see your custom tag unaltered.


    Ken

  2. March 3, 2008 at 5:25 am | Permalink

    I guess you might be outputting some namespaced XML, in which case “” would be perfectly valid output and you wouldn’t want CF to pick it up and throw an error.

    It might be nice if you could do a cfimport “mapping” though, so that you didn’t need to include the same cfimport statement on every page… That way you don’t forget it, and you write less code :)

  3. March 3, 2008 at 5:28 am | Permalink

    Ah thanks guys, that is of course totally obvious now that I stop to think about it!

    hehe, thanks for the input :)

  4. March 26, 2008 at 8:20 am | Permalink

    C5XW5p hi good site thx http://peace.com

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*