Scripting Syntax
The
<cfscript> and
</cfscript> tags are at the heart of the
CFScript language. All CFScripting in a template takes place between
these tags. There are a few general guidelines that will help you
write your CFScripts:
cfscripttag pairs can be placed anywhere in your template.More than one set of
cfscripttags can be placed in your template.cfscripttags may not be nested.Code (including variable names) placed between
cfscripttag pairs is case-insensitive.CFML tags may not be used within a
cfscripttag block.CFML functions may be used within a
cfscriptblock.CFML variables created outside a
cfscriptblock are automatically available within the block.Not all CFML variables created inside the
cfscriptblock are automatically available outside of the block.CFScript statements end in a semicolon.
Curly braces (
{ }) are used to group related statements.
Working with Variables
Assigning values to variables in CFScript is simple. Assignment statements take the following form:
variable = expression;Here, variable is the name of the
variable, and expression is the value you
wish to assign to the variable. The semicolon marks the end of the
statement. For comparison sake, consider the following example in
which we assign values to a number of variables using the
cfset tag:
<cfset x = 1> <cfset y = 1+2> <cfset MyMessage = "Hello World"> <cfset MyStructure = structNew( )>
The same functionality can be rewritten using CFScript syntax like so:
<cfscript> x = 1; y = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access