Displaying information is one of the first things every developer learns. Whether you're showing a welcome message, printing a variable, displaying database records, or building an HTML page, your application needs a way to send output to the browser.
ColdFusion provides two primary ways to display content: writeOutput() in CFScript, and <cfoutput> in Tag Syntax. Both produce the same result โ the only difference is the syntax you choose.
By the end of this lesson, you'll understand when to use each approach, how to display variables and expressions, and the most common output techniques used in real ColdFusion applications.
Learning Objectives
After completing this lesson, you'll be able to:
- Display text using writeOutput().
- Display text using <cfoutput>.
- Output variables.
- Output expressions.
- Combine text with variables.
- Understand when to use writeOutput() vs <cfoutput>.
What Is Output?
Output is the content sent from the ColdFusion server to the user's browser. For example, when your page displays "Welcome John," ColdFusion generated that text and sent it to the browser.
Without output functions, users wouldn't see anything.
writeOutput() (CFScript)
writeOutput() is a built-in function that displays text or variable values. Syntax: writeOutput(value);
<cfoutput> (Tag Syntax)
In tag-based CFML, output is usually generated using the <cfoutput> tag.
Outputting Variables
Variables don't automatically appear on the page. You must explicitly output them.
Inside <cfoutput>, variables must be wrapped with # symbols.
Output Multiple Variables
Output Expressions
You can display the result of calculations directly.
Combine Text and Variables
This is one of the most common tasks.
Display HTML
ColdFusion can output HTML along with dynamic values.
Both render as an <h2> heading in the browser, not literal <h2> text.
Output Multiple Lines
Output Current Date
Your actual output will differ, since now() always returns the current date and time.
Real-World Example
writeOutput() vs <cfoutput>
| writeOutput() | <cfoutput> |
|---|---|
| Used in CFScript | Used in Tag Syntax |
| Function | Tag |
| Prints values immediately | Prints everything inside the tag |
| Ideal for script-based code | Ideal for tag-based pages |
| No # required | Variables require #variable# |
Visual Overview
Common Beginner Mistakes
Forgetting # inside <cfoutput>
<cfoutput>name</cfoutput> prints the literal word "name", not the variable's value. You need <cfoutput>#name#</cfoutput> โ the # symbols tell ColdFusion to evaluate it as an expression.
Using writeOutput without parentheses
writeOutput "Hello"; is invalid CFScript syntax. It's a function call, so it needs parentheses: writeOutput("Hello");.
Forgetting to concatenate text
writeOutput("Hello" name); is a syntax error. Join the string and variable with &: writeOutput("Hello " & name);.
Mixing Script and Tag Syntax incorrectly
Writing <cfoutput> directly inside a <cfscript> block doesn't work โ <cfoutput> is a tag, and CFScript is script code. Keep CFScript and Tag Syntax separate unless you intentionally switch contexts between them.
Best Practices
- Prefer writeOutput() when writing CFScript.
- Prefer <cfoutput> when writing tag-based CFML.
- Use meaningful variable names.
- Keep HTML separate from business logic whenever possible.
- Escape user-generated content before displaying it (covered later in the Security module).
Interview Questions
What is writeOutput()?
A built-in CFScript function used to send output to the browser.
What does <cfoutput> do?
It outputs text, variables, and expressions in tag-based CFML.
Why are # symbols required inside <cfoutput>?
They tell ColdFusion to evaluate the expression instead of treating it as plain text.
Can writeOutput() display variables?
Yes โ for example, writeOutput(name); displays the value stored in the name variable.
Which is better: writeOutput() or <cfoutput>?
Neither is better. They produce the same output. Use writeOutput() in CFScript and <cfoutput> in tag-based code.
Summary
In this lesson, you learned how ColdFusion sends content to the browser using writeOutput() in CFScript and <cfoutput> in Tag Syntax. You displayed text, variables, expressions, HTML, dates, and combined multiple values into meaningful output.
Understanding output is essential because nearly every ColdFusion application displays dynamic information to users. Whether you're showing a welcome message, rendering database results, or generating an entire web page, these two output methods are the foundation of dynamic content in ColdFusion.
What's Next?
The next lesson covers Strings โ how to create, concatenate, compare, search, split, replace, and manipulate text using ColdFusion's built-in string functions in both CFScript and Tag Syntax.