Monday, January 19, 2009

Widely used ColdFusion Tags

Like HTML ColdFusion also works on a set of predefined tags. Some of the more important and widely used tags are placed below.

1) CFINCLUDE – This tag is used to reference a ColdFusion file or other documents. Including files allows us to use repetitive code without having to write them over and over again.

It takes up one attribute TEMPLATE and the syntax is

<CFINCLUDE TEMPLATE = “file_name>

2) CFIF - As the name specifies it the same as any of the “IF” in all the other languages.

 <CFIF condition >
         expression 1
<CFELSE>
         expression 2
</CFIF>

There is also an IIF tag which is similar to the ternary operator in java,

IIF( condition, expression 1 ,expression 2)

Where the expression 1 is evaluated when the condition is true and the expression 2 is evaluated when the condition is false.

3) CFLOOP - CFLOOP is a looping tag of ColdFusion.

 <CFLOOP INDEX = “index_name”"
         FROM = “start_numberTO = “end_numberSTEP = “increment>

4) CFSET - This tag is used to set the value of a ColdFusion variable

 <CFSET variable_name = “value>

5) FORM - Builds a form with CFML custom control tags, thus provide more functionality than standard HTML form input elements.

<CFFORM ACTION = “Form_submit>      ...    </CFFORM>

The input elements are place in between the closing and ending form tags. These can be anything varying from textbox, radio button, checkboxes etc.

6) CFQUERY – This tag is used to retrieve the data from the database. You can either pass a sql statement or call a stored procedure into it.

<CFQUERY NAME = “query_nameDATASOURCE = “database_name>   ...   </CFQUERY>

7) CFOUTPUT - This tag is one of the most widely used tags in ColdFusion. This is usually used in conjunction with the CFQUERY tag to display the output from the query.

 <CFOUTPUT QUERY = “query_name>    ...   </CFOUTPUT>

The query attribute in the CFOUTPUT is used to relate the output to the query, specifying that the output is of a particular query. The display formatting of data can be done in this tag using HTML tables, etc.

All the start tags in ColdFusion should have a matching end tag, which is mandatory.

The pound (“#”) is an important sign in ColdFusion and is used with variables whose name are used as strings, but can be eliminated in most cases.

#variable_name#

Reference :  Programming ColdFusion