Basic Grammar in ColdFusion

I would like to share basic grammar in ColdFusion.

🎉 How ColdFusion Work

ColdFusion code is compiled into Java byte-code. ColdFusion is made up of two parts:

  • ColdFusion Application Server
  • ColdFusion Markup Language (CFML)

🍄 What is ColdFusion Markup Language

  • The ColdFusion Markup Language (CFML) looks similar to HTML in which is tag-based.(e.g, <cfloop>)
  • CFML is also includes fully functionally built-in scripting language similar to JavaScript

🎂 Cheat Sheet for Basic Grammer


<!--- Original Variable --->
<cfset VARIABLES.greeting="Hello">

<!--- Passing Variables on the URL (HelloHi.cfm?greet=Hello) --->


<!-- This is an HTML comment -->
<!--- This is a ColdFusion comment --->

Builtin Functions

ColdFusion has a lot of functions for performing all sort of tasks, etc.

#DateFormat(Now(),"dddd, mmmm d, yyyy")#

If you want to know more detail, please see ColdFusion functions by category

Arithmetic and String Operation

ColdFusion has some Arithmetic and String Operations:

<!--- Atrithmetic Operation --->
<cfset c = a + b>

<!--- String Operation --->
<cfset c = a + b>

If you want to know more detail, please see Expressions-Developing guide

Conditional Processing

<!--- If-Else if-Else Blocks --->

<!--- Switch Blocks --->
<cfset Quantity = 1>
<cfswitch expression="#Quantity#">
<cfcase value="1">Quantity is 1</cfcase>
<cfdefaultcase>Quantity is not 1</cfdefaultcase>


<cfset numlist="1,2,3,4,5">
<cfloop index="num" list="#numlist#">

If you want to know more detail about List functions, please see List functions


<!--- One-dimensional Arrays -->
<cfset beatles = ArrayNew(1)>
<cfset ArrayAppend(beatles,"John")>
<cfset ArrayAppend(beatles,"Paul")>

<cfloop from="1" to="#ArrayLen(beatles)#" index="i">

<!--- Two-dimensional Arrays -->
<cfset rockbands=ArrayNew(2)>
<cfset rockbands[1][1]="Beatles">
<cfset rockbands[1][2]="Love Me Do">

<cfloop from="1" to="#ArrayLen(rockbands)#" index="i">
<cfloop from="1" to="#ArrayLen(rockbands[i])#" index="j">

If you want to know more detail about Array functions, please see Array functions


HTML with form:

<!--- Use HTML form --->
<form method="post" action="form-receive.cfm">
<input name="yourname" type="text" size="30">
<input type="submit" value="submit">

<!--- Use cfform tag --->
<cfform name="RunningForm" method="post" action="AddEntry-cfform.cfm" format="html">
<cfinput type="text" name="date" size="20">
<cfinput type="submit" name="Add Entry" value="Add Entry">

Receive form data:

<b>Your name:</b> #FORM.yourname#

cfform tag supports validation:

Suffix Description
numeric Accept only Numeric input
require Check that the value exists
email Valid email address

🐰 Next


🚕 Special Thanks

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!