DevLearningTools

MODULE 9 · LESSON 03

cfimport

Calling custom tags under your own namespace prefix with <cfimport> — taglib and prefix, importing multiple libraries, and how it compares to the cf_ naming convention.

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

<cfimport> loads a whole directory of custom tags at once under a namespace prefix you choose, instead of relying on the cf_ naming convention and the specific storage-location rules a plain custom tag needs.

Learning Objectives

After completing this lesson, you'll be able to:

  • Import a directory of custom tags with cfimport, and call them under a chosen prefix.
  • Import more than one tag library into the same page with different prefixes.
  • Explain when cfimport is a better fit than the cf_ prefix convention.

Basic Syntax

Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

taglib points to the directory holding the tag files, as a web-root-relative path starting with /. prefix is entirely your choice — ui here, but it could be anything.

taglib Path Resolution

Path styleResolved from
Web-root-relative ("/customtags")The site's document root
A mapped path ("/ui-tags")A mapping configured in the ColdFusion Administrator
NOTE

Every file in the taglib directory becomes callable through the chosen prefix — there's no need to import each tag individually.

Importing More Than One Tag Library

Tag Syntax
<cfimport taglib="/customtags/forms" prefix="form">
<cfimport taglib="/customtags/layout" prefix="ui">

<ui:header pageTitle="Home">
<form:textInput name="email" label="Email Address">
<ui:footer>
NOTE

Each cfimport call is independent — different directories, different prefixes, used together freely on the same page.

cfimport vs the cf_ Prefix Convention

cf_ Prefixcfimport
Storage locationSpecific directories required (same folder, CustomTags, or an Administrator mapping)Any directory — declared explicitly as taglib
NamingFilename must start with cf_ to be callable that wayAny filename, called through your chosen prefix
Calling many tags from one placeEach call resolves its own location independentlyOne import call covers every tag in that directory
Best forA quick, occasional custom tagA whole reusable tag library used repeatedly across a project
NOTE

Both ultimately call the same kind of custom tag file — the isolated Attributes/Caller scope behavior is identical either way. cfimport only changes how the tag is located and named at the call site.

Common Beginner Mistakes

Forgetting that prefix is arbitrary

prefix isn't tied to the directory name or anything else — it's just the label you'll type before each tag. Pick something short and clear for the tag library it represents.

Expecting taglib to accept a relative path

taglib is resolved as web-root-relative (or through an Administrator mapping) — a plain relative path like "customtags" without the leading slash won't reliably resolve the way a cfinclude path does.

Assuming cfimport changes how the tag itself behaves

It doesn't — the tag file still runs in its own isolated scope with Attributes in and Caller out, exactly like calling it with a cf_ prefix. cfimport only changes how it's located and named at the call site.

Best Practices

  • Prefer cfimport with a clear, project-specific prefix over the cf_ convention for a tag library used repeatedly across a project.
  • Keep each tag library in its own directory so one cfimport call cleanly covers all of it.
  • Choose prefixes that describe the library's purpose (ui, form, report) rather than something generic.

Interview Questions

What do taglib and prefix each do on <cfimport>?

taglib is the web-root-relative path to the directory holding the custom tag files. prefix is the namespace you choose to call them under — entirely up to you.

Does cfimport change how a custom tag's scope works?

No — the tag still runs in its own isolated scope, receiving data through Attributes and returning it through Caller, exactly as it would if called with a cf_ prefix.

Why choose cfimport over the cf_ naming convention?

cfimport removes the cf_ naming requirement and the specific storage-location rules, and lets one import call make an entire directory of tags callable under a chosen prefix — better suited to a tag library used repeatedly across a project than the cf_ convention's per-tag, per-location resolution.

Can you import more than one tag library into the same page?

Yes — each cfimport call is independent, so a page can import several directories under different prefixes and use them together.

Summary

In this lesson, you used cfimport to call custom tags under a chosen prefix instead of the cf_ convention, imported multiple tag libraries into the same page, and compared cfimport to the cf_ prefix convention.

What's Next?

The next lesson covers cfmodule — another way to call a custom tag, by path or dotted name, without needing the cf_ prefix, a specific storage location, or a taglib import.

MORE IN REUSABLE CODE