Skip to content


kjerk edited this page Oct 17, 2013 · 6 revisions

Next section Variables

1. Syntax

There are two ways to write CFML code. You can use tag or script syntax. For the examples, please focus on one or the other so this tutorial is not confusing.

CFML includes a set of instructions you use in pages. You will write one or more instructions in a file then run the file through a CFML engine. Three CFML instructions we will use in this tutorial are CFSET, CFOUTPUT, and CFDUMP. CFSET is used to create a variable and assign it a value. Also CFSET is used to call methods. CFOUTPUT displays a variable's value. CFDUMP is used to display the contents of simple and complex variables, objects, components, user-defined functions, and other elements.

We might have a file named myprogram.cfm and Sample.cfc like this:

Tag Syntax


<cfset s = New Sample() />


    <cffunction name = "hello">
        <cfreturn "Hello, World!" />

Script Syntax


    s = New Sample();


component {
    public string function hello() {
       return( "Hello, World!" );

For the script example, myprogram.cfm would have beginning/closing <cfscript> tags around the instructions, however, the script-based Sample.cfc does not require <cfscript> tags around the instructions.

PHP Syntax


    $s = new Sample();
    echo $s->hello();


class Sample
    public function hello() {
        return "Hello, World!";

Ruby Syntax


class Sample
    def hello
        "Hello, World!"

s =
puts s.hello

Next section Variables

Something went wrong with that request. Please try again.