Chapter 18. Scripting

When Allaire released ColdFusion 4.0, they introduced a new server-side scripting language called CFScript. CFScript is similar in appearance to JavaScript and allows you to write sections of code in your templates using a more concise format than tag-based CFML. CFScript isn’t meant to replace the CFML language; it just provides you with a choice for coding your pages. Additionally, with the introduction of ColdFusion 5.0, CFScript includes the ability to create user-defined functions. Those used to programming in JavaScript will find the CFScript constructs quite familiar.

This chapter covers everything you need to know about the CFScript language, along with examples.

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:

  • CFSCRIPT tag pairs can be placed anywhere in your template.

  • More than one set of CFSCRIPT tags can be placed in your template.

  • CFSCRIPT tags may not be nested.

  • Code (including variable names) placed between CFSCRIPT tag pairs is case-insensitive.

  • CFML tags may not be used within a CFSCRIPT tag block.

  • CFML functions may be used within a CFSCRIPT block.

  • CFML variables created outside a CFSCRIPT block are automatically available within the block.

  • Not all CFML variables created inside the CFSCRIPT block are automatically available outside of the block.

  • CFScript ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.