I noticed recently in a mailing list response to the announcement of Daemon's open source CMS for ColdFusion MX, FarCry: http://farcry.daemon.com.au, that there may be some confusion over the use of the CFIMPORT tag.
The post in question observed that if the CFIMPORT tag was being used it must be to import JSPs, a valid reason for CFIMPORT, what the poster didn’t realize was that CFIMPORT also allows a developer to import all custom tags from a specified directory as a library with a single call.
It creates a new approach to how ColdFusion custom tags are accessed and deployed.
The tag attributes are: taglib– the relative path to the directory where the ColdFusion custom tags are stored; and prefix – the prefix that the tags will be referenced by within the page doing the calling e.g.
<cfimport taglib="customtags" prefix="siteTags">
Using a relative path for the location of the custom tags proves useful for deployment of code as it means that you can basically just pick everything up and plonk it down where you want it hosted.
Unfortunately the taglib attribute does not support the use of ColdFusion mappings which would have made the CFIMPORT even more useful, let’s hope that future versions of CFMX will address that.
CFIMPORT will import all the tags in the nominated directory making them available to the calling page. The tags are then called using the methodology: prefix:tagname, followed by attribute="value" if required e.g.
<siteTags:now type="date">
Custom tags called using CFIMPORT can, with the appropriate internal application design, have close tags, as well as make use of nested sub tags e.g.
<siteTags:processingTime>
CFML & HTML to be processed by tag
</siteTags:processingTime>
Putting all the above example code together we might have something within a page that could look like this:
<cfimport taglib="customtags" prefix="siteTags">
<siteTags:processingTime>
<siteTags:now type="date">
</siteTags:processingTime>
Sample code is available for you to test out the examples above, plus a little more, from this download link.
Posted by at 03:35 PM | Permalink
Trackback: http://blog.daemon.com.au/cgi-bin/dmblog/mt-tb.cgi/114


There is also an example of importing custom tags in the example apps that ship with ColdFusion.
Posted by: Raymond Camden on April 29, 2003 05:54 AM
One cool thing you can do with this is to split your tags into groups. So you can have ui tags, security tags, etc. This makes your code a bit more readable since you can have stuff like...
<security:authorize foo=1>
and
<ui:form type="text">
Posted by: Raymond Camden on April 29, 2003 05:55 AM
I so love CFIMPORT, so much easier to make apps portable while stilling having the flexibility of storing customs tags in one location within your web account (Not all ISPs will give you custom tag directory).
It rox.
Posted by: Scott Barnes on May 2, 2003 12:08 PM
Actually, Cold Fusion mappings are supported in the CFIMPORT. One thing that should be noted is that you may have to make the mapping in your C:\CFusionMX\wwwroot\WEB-INF\jrun-web.xml file to make sure that the mapping sticks.
I make extensive use of it actually in my site and love the way they function. I think that they serve a great role in the overall flow of things.
I did a little brief look at its use for my user group last month:
http://66.93.91.18:777/demo/April_2003/
The major gotchya is that you can use a variable in the folder.. that would have been incredibly useful.. but there are good reasons for it.
Posted by: Gregory Narain on May 2, 2003 03:56 PM
Greg
"you may have to make the mapping in your C:\CFusionMX\wwwroot\WEB-INF\jrun-web.xml file to make sure that the mapping sticks"
means that you're taking advantage of a web server mapping, not a CFMX mapping...
Posted by: Andrew Muller on May 2, 2003 04:02 PM
Andrew..
Good point.. didn't consider that at first. probably cuz the last time I looked it up was here:
http://www.cfczone.org/blogs/rob/2002_10_01_archive.cfm
Which provides an additional, though possibly uglier, solution.
Ahh well.
Posted by: Gregory Narain on May 8, 2003 03:57 PM