ColdFusion Markup Language

From Wikipedia, the free encyclopedia

ColdFusion Markup Language, more commonly known as CFML, is the scripting language used by Adobe ColdFusion and several alternative server environments, including BlueDragon, Coral Web Builder, IgniteFusion, Railo. It is similar to HTML in that it uses tags, need not be well-formed, and includes a built-in script tag to allow inline scripting within markup.

[edit] Syntax

Tags which are included in the core runtime are always prefixed with a cf followed by unique identified, starting with a letter. Custom tags written in CFML may be prefixed with cf_, although there are other ways to invoke them.

Procedural style functions are available throughout a CFML script.

CFML is generally considered a dynamic language. However, various tags offer the ability to type-check input parameters (eg: cffunction, cfparam, cfqueryparam) if the programmer declares their type specifically. It is debated whether this is good practice, as failure occurs at runtime regardless of whether type checking is used or not.

CFML is case insensitive.

CFML relies heavily on maps, where the keys are always strings and the values are not type specific. Values are often access using dot notation, but -- depending on the CFML implementation -- can be accessed via procedural functions, or can be treated as objects where instance get methods are invoked.

Recent CFML implementations include support for objects, known as components. Components definitions reside in a file, and is surrounded by cfcomponent tags.

Message passing to components is also done via dot notation, similar to other object-oriented languages such as Java. If omitting the open and close brackets of a method invocation, ColdFusion will treat the function as the value object a map. This allows methods to be treated as first-class objects.

CFML need not be well-formed. If it is legal for tags not to have a body, it is syntactically acceptable to leave them unclosed. For example:

<cfset value = "hello">

The self-closing variant

<cfset value = "hello"/>

is also legal. Which style should be used is an often debated issue.

[edit] Custom Tags

CFML allows language extensions in the form of custom tags. Custom tags are normal files which are intended to be invoked as tags, although it is possible to treat a template as both a custom tag and a regular template.

If a template is invoked as a custom tag, the attributes used to invoke that tag are available in a special structure attributes and the variables on the calling page are accessible via the caller' struct. For example, if writing an add tag which takes two attributes and adds them together, the add.cfm page would look like this:

<cfset caller.sum = attributes.first + attributes.second / >

The tag can be invoked thusly:

<cf_sum first="1" second="2">

assuming the template and tag are in the same directory.

[edit] See also