Blog

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:

start

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:

127.0.0.1:<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

Into the Box 2024 - Conference Slides are out!

Into the Box 2024 - Conference Slides are out!

Did you miss the live event? Get a glimpse of the fantastic content our speakers covered by reviewing their slides. Dive into topics like AWS, Cloud, Hosting, Migration, Security, CFML, Java, CommandBox, ContentBox, and more. Don't miss these valuable resources, and join us for upcoming events!

Maria Jose Herrera
Maria Jose Herrera
July 03, 2024
Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024