Now that you've read my Why Coldfusion? post (you HAVE, right?), let's do a simple Hello World just to try some sample CF code.
Installing Coldfusion is as easy as downloading Commandbox and dropping it in a folder. On Linux, you'll want to drop it in a folder somewhere in your
$PATH - perhaps
/usr/bin? Otherwise (Windows or Mac) just drop it in a folder and drag the box executable to your taskbar to give yourself a nice quick launcher icon.
Let's do a quick Hello World so we know what we're up against.
- Create a
hello.cfmfile. Somewhere. (Anywhere!)
- Edit that
- Type in the following code:
<cfscript> writeOutput( 'Hello, World!' ); </cfscript>
Ok, so this is the gist of a modern Coldfusion markup (
.cfm) file. This file is doing two things:
<cfscript></cfscript>to denote the Coldfusion script syntax
This is just CF's version of PHP's
<?php ... ?> delimiters. Now, there is a fully-supported, fully-capable tag syntax, but I prefer the script syntax for pretty much everything but templating. I think on the whole, modern CF apps are better off using CFscript syntax - but that's just my opinion. Oh, and you only need this
<cfscript> tag in
.cfm files - anything in a component (a
.cfc file)can launch right into script syntax.
- Using the
writeOutput()function to print a string value to the buffer
This is hopefully straightforward - we're writing output to the buffer. In this example, we're going to use CommandBox to run the file, so the output will be returned inline to the CommandBox CLI.
Executing a CFM File in CommandBox
Here's how we run our
hello.cfm file using CommandBox. First, you'll need to start Commandbox by clicking on the launcher or typing
box in your Mac/Linux terminal. Once in CommandBox, we'll use the
execute command to run the script and return the output:
Boom! It's that easy to try Coldfusion*. There's no compiling, no building, and no downloading hundreds (or thousands) of dependencies - just run the script.
If you want to see exactly what that looks like, here you go.
*Please note that this is not a production-ready format - for that you'd want to run
server start email@example.com to install and start the open-source Lucee server. Let me know if you'd like to see a tutorial about that as well - I'm happy to help you get started!
Latest comments (0)