Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

Framework One for when you don't need a framework pt2

This post follows on from my first part and is all about using a framework for even the most simplest sites.

So our family member, Marvin Acme, has come back with the layout for his ACME gadgets to capture and kill rodents site.
Site layout

Being a family member means we're getting paid most likely with canned beer and with that in mind they are not getting me working on stylesheets!

  1. Create a new folder called layouts in the root of /acme/ and add a file called default.cfm. In there place the following snippet:
    view plain print about
    1<cfparam name="rc.pagetitle" default="A.C.M.E">
    2&lt;html>

    3<head>
    4&lt;title><cfoutput>#rc.pagetitle#</cfoutput></title>
    5&lt;style>*{font-family:"Comic Sans MS";text-align:center;}</style>
    6</head>
    7<body>
    8<cfoutput>
    9<div id="wrap">
    10<h1>A.C.M.E - Outlandish and downright dangerous products</h1>
    11<div id="nav">
    12<a href="#buildURL(framework.home)#">Home Page</a> |
    13<a href="#buildURL('main.about-us')#">About Acme</a> |
    14<a href="#buildURL('main.contact-us')#">Contact Us</a>
    15</div>
    16#body#
    17<div id="footer">A.C.M.E &copy #year(now())#</div>
    18</div>
    19</cfoutput>
    20</body>
    21</html>
    There are 3 elements in here that relate to the framework
    1. #rc.pagetitle#: the "rc" refers to the Request Context and contains all the URL and form variables from the browser which are also made available to the view directly. We can also update this variable from within a view for the default.cfm to read, in this case to update the page title
    2. buildURL simply creates the index.cfm?action= strings for us. You reference the folder name within the views/ folder (in this instance we called it main) and the file name (without the .cfm extention)
    3. #body# is where our view file will be populated in to. There is a lot more to the layouts than I need to go in to here so make sure you check out manual to see what else you can do.
  2. In views/main/ add about-us.cfm. In there put the following code:
    view plain print about
    1<cfset rc.pageTitle = "About A.C.M.E" />
    2<p>About us text coming soon</p>
  3. In views/main/ add countact-us.cfm. In there put the following code:
    view plain print about
    1<cfset rc.pageTitle = "Contact A.C.M.E" />
    2<p>Contact us text coming soon</p>
  4. In views/main/default.cfm replace the currect code with the following:
    view plain print about
    1<p>New site coming soon</p>

You should now be able to go to localhost/acme and see the following:
The site

You're done - obviously minus the content but your 3 page brouchware is setup. No XML config files, setting up debug mode, and thinking about your event names ahead of time head of time.

What is so great about this then?

  • The speed! Yes we could of used no framework and cfmodule on default.cfm, contact-us.cfm, and about-us.cfm but thats a lot of edits to do if the location of cfmodule changed or you wanted to add a required attribute. Look at what has been achieved and we spent no time setting the site up and got all the benefits of having a framework!
  • If Marvin came back and wanted a form or some kind of data displayed we have the benfit of the framework and its abiltiy in handling and passing data around.
  • And again speed! All you've done is created/edited 4 files! No more than if you would of done this without a framework!

Hopefully you've seen that there is no reason not to use a framework even in the smallest of projects. We've managed to create a site and not have to think about MVC or OO (or even XML config files) but at the same time whilst still having the power of these methodologies in the background in case we need them. Don't see this as I am against MVC or OO its just for some apps you don't need to think about these principles and convention over configuration has made this possible.

In keeping with the series I have some more posts as Marvin already has some idea posting and retrieving data and I'll look at how to grow the site.

Found out more about Framework One via:

Comments Comments (8) | Print Print | Send Send | 1337 Views

Related Blog Entries
(Comment Moderation is enabled. Your comment will not appear until approved.)
Hi Andy,

For a webstore, how to implement? I do not want a CFM page for every unique page coming out of the database. Same with a plain and simple vanilla site. I want ONE layout file where all the logic is contained.

Not having jumped on the FW/1 bandwagon yet, is this bad? I'm currently using FB3.x (with CFC's) and FB5.5 noxml for most of my sites and apps. How does FW/1 make my life simpler? Your examples don't seem very convincing to me, for now...

PS: Where's the next nice CSS for your blog? You've had so many, this one is a little boring ;-)
@Sebastiaan My example isn't for you :) My example for for people who build very flat and simple sites. Usually people would't use a framework for just a 3 page site but with FW/1 I wanted to demonstrate that you still can and in just case the site ever grows you already have your building blocks to create an application.

For something thats more complex like a webstore look at downloading FW/1 (http://github.com/seancorfield/fw1) and looking at the example apps in there. Sean Corfield & co have done a great job with demos and documentation for such an infant framework!

As for the site design I was going for something akin to Posterous but will be updating soon :)
Lola LB's Gravatar Posted By Lola LB @ 6/9/10 4:37 PM
Strange . . . I these steps and when I go to localhost/acme, all I'm getting is the text "New site coming soon". I even copied/pasted the code for default.cfm just to doublecheck. Any ideas what could be going on?
@lola did you follow part one to see the "Hello FW/1" message? Can you create any folder off the root of Localhost and view it?
pjh's Gravatar Posted By pjh @ 6/14/10 2:28 PM
I believe the folder name should be layouts - not layout. This might address Lola LB's issue.
@pjh good spot Updating the site now
Lola LB's Gravatar Posted By Lola LB @ 6/14/10 4:14 PM
@pjh . . Yep, that was the issue. Good catch!
Great Tutorial!
BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .