CommandBox: CFML SandBox

Nathaniel Francis February 18, 2015

Spread the word

Nathaniel Francis

February 18, 2015

Spread the word

Share your thoughts

CommandBox = CLI for CFML

For a long time, the CFML community has wanted a CLI tool for REPL, developer productivity, tool interaction, embedded CFML server, and application scaffolding. CommandBox provides those elements.

But what about just playing with CFML? There's the REPL in CommandBox of course, but what if I want to do something a bit larger than that and really play with the language?

SandBox = CommandBox + ColdBox

Creating a SandBox environment is surprisingly easy. All you need are 2 things:

  1. A working version of CommandBox
  2. A simple ColdBox 4.0 install

Why ColdBox?

When most people see "ColdBox", they think of the full-fledged, super extensible framework, according to its reputation. But there are some very simple, "out of the way" aspects that ColdBox provides. One of which will help us setup a SandBox within which we can play with CFML in a larger scope than the CommandBox REPL provides.

That feature is: implicit views. For a long time, the ColdBox framework has employed a mechanism called implicit views. You simply place a .cfm file into the directory's views folder and ColdBox will implicitly map to that .cfm file even if it doesn't have a corresponding event handler. Simply put, write a .cfm file and we can hit it without any extra hoopla or work. Pretty simple.

Armed with ColdBox 4.0's implicit views and CommandBox's embedded server, you can setup a quick and easy SandBox that can run right in your local system.


NOTE: this is not about learning ColdBox per se (although that's pretty cool too). It's about being able to simply play with CFML beyond the CommandBox REPL.


SandBox Setup

Step #1: mkdir/cd

Start by opening CommandBox and "cd" to whatever directory you want to make a simple app.

Then make a directory to house your SandBox.

mdir mySandBox
cd mySandBox

Step #2: simple ColdBox install

Now, put in a simple ColdBox 4.0 installation into the directory. You don't need any additional modules or libraries, the basic ColdBox install is all you need.

coldbox create app sandbox --installColdBox

If this is your first ColdBox install, it will take a little bit to get the files from ForgeBox. If you've made a ColdBox app before, CommandBox will load the files from your local artifacts in a moment.

Now, you can look in your mySandBox directory and see the files that the ColdBox install setup for you.

Step #3: make a .cfm file

To start SandBoxing, you're going to make a simple .cfm file from CommandBox.

coldbox create view hello

If you check your directory, under the views folder, CommandBox has generated a simple "hello.cfm" file.

Open that "hello.cfm" file in a text editor and you will see this:

<h1>hello view</h1>

Pretty simple.

Step #4: start the embedded server

Now to make it live: go back to CommandBox and simply enter:


This will start CommmandBox's embedded server with the SandBox application in your default browser.

What you'll see come up in your browser is a standard Welcome To ColdBox! page that gives detailed information of your simple ColdBox app.

Now you need to get to your "hello.cfm". ColdBox will map to the "hello.cfm" file by appending the name of the file to index.cfm. Simply enter this in your browser's URL field:<port#>/index.cfm/hello

And you will see this:

Just the beginning

This is just the beginning. Now you can go to your text editor and start playing with CFML right there. On browser refresh, you'll see the changes go live. We got a real CFML SandBox with nothing more than CommandBox and a simple ColdBox install (thanks to ColdBox's implicit view mechanism and CommandBox's embedded server).

As an example, in my own SandBox, I went my "hello.cfm" file and entered the following:

The <h1>hello view</h1> was already there (created automatically from Step #3). I simply added a dump of now() and my session scope.

Refresh the browser and I get this:

There. Now I'm doing more than the CommandBox REPL provides. I'm able to genuinely SandBox with CommandBox.

Happy SandBoxing!

Add Your Comment

Recent Entries

CBWIRE 2.2 Released

CBWIRE 2.2 Released

We're excited to announce the release of CBWIRE 2.2. This release includes several added enhancements, such as new lifecycle hooks and simplified Turbo Drive integration. We changed the previous lifecycle hook of mount() to onMount() to be consistent, and several bugs were squashed.

Maria Jose Herrera
Maria Jose Herrera
January 09, 2023
FORGEBOX v7.1.0 Released

FORGEBOX v7.1.0 Released

We are so happy to announce a minor release for our package management system. In this release, we take care of some bug fixes reported and a lot of work for our elastic search engine. Now better search results with an improved response time. We have updated our core modules to the latest versions for better security and performance.

Javier Quintero
Javier Quintero
December 30, 2022
Favorite 2022 Ortus Content

Favorite 2022 Ortus Content

2022 was quite the year. For us, it was all about delivering exceptional content and service to our amazing community of developers. That's why we updated our tools, released new products, and announce upcoming projects and initiatives we are working on for 2023.

We know 2023 will be awesome but 2022 was amazing too. Read on and don't miss anything, review the top content we released in 2022 and improve your projects in 2023. Happy New Year!

Maria Jose Herrera
Maria Jose Herrera
December 29, 2022