Working with TemplatesBack in Chapter 4, "Previewing ColdFusion," I walked you through creating several simple applications. ColdFusion applications are made up of one or more files, each with a .cfm extension. These files often are referred to as templates; you'll see the terms templates, files, and even pages used somewhat interchangeably. Just so you know, they all refer to the same thing. I'll explain why the term templates is used in a few moments.Chapter 3, "Accessing the ColdFusion Administrator," the URL used with ColdFusion will vary based on whether or not an external Web server is being used. For the sake of simplicity, all URLs used in this and future chapters assume that ColdFusion is being used in conjunction with the integrated Web server ("standalone" mode). As such, you'll see the port address :8500 specified in all URLs (both in the content and the figures). If you are not using the integrated Web server simply omit the :8500 from any URLs. Creating TemplatesAs already explained, ColdFusion templates are plain text files. As such, they can be created using many different programs. Obviously, a good choice for ColdFusion developers, as already seen, is Macromedia Dreamweaver MX. So that's what you'll use here and throughout the rest of this book.To create a new ColdFusion fileor template; as I said, the terms are used interchangeablysimply start Dreamweaver MX. The editor will be ready for you to start typing code, and what you save is the ColdFusion file, as long as you save it with a .cfm extension, that is. NOTEThere are two other file extensions used with ColdFusion, .cfc and .cfr. We'll look at those files in future chapters.The code shown below is the contents of a simple ColdFusion file named hello1.cfm. Actually, at this point no ColdFusion code exists in the listingit is all straigh275 and text, but we'll change that soon. Launch Dreamweaver MX (if it is not already open), and type the code as shown next (see Listing 8.1).Listing 8.1. hello1.cfm
TIPTag case is not important, so <BODY> or <body> or <Body> can be usedit's your choice.Saving TemplatesBefore ColdFusion can process pages, they must be saved onto the ColdFusion server. If you are developing against a local server, with ColdFusion running on your own computer, you can save the files locally. If you are developing against a remote server, you must save your code on that server.Where you save your code is extremely important. The URL used to access the page is based on where files are saved, and how directories and paths are configured on the server.As explained back in Chapter 2, all the files you create throughout this book will go in directories beneath the ows directory under the Web root. To save the code you just typed, create a new directory named 8 under ows and then save the code as hello1.cfm. To save the file, do one of the following:
TIPForgotten how to create directories in Dreamweaver MX? Here's a reminder: In the Files window select the directory in which the new directory is to be created, right-click in the file pane below, and select New Folder.Executing TemplatesNow, let's test the code. There are several ways to do this. The simplest is to right-click on the file in the Files window and select Preview in Browser (selecting your browser off the list).You may also execute the page directly yourself. Simply open your Web browser and go to this URL: http://localhost:8500/ows/8/hello1.cfm TIPNot using the integrated Web server? See the note at the start of this chapter.You should see a page like the one in Figure 8.1. I admit that this is somewhat anticlimactic, but wait; it'll get better soon enough.Figure 8.1. ColdFusion-generated output usually is viewed in any Web browser.[View full size image] ![]() Figure 8.2. If configured correctly, you'll be able to browse much of your Cold Fusion code within Dreamweaver itself.Chapter 2, "Introducing Macromedia Dreamweaver MX;" refer to that chapter if necessary. Templates ExplainedI promised to explain why ColdFusion files are often referred to as templates. Chapter 1, "Introducing ColdFusion," explains that ColdFusion pages are processed differently from Web pages. When requested, Web pages are sent to the client (the browser) as is, whereas ColdFusion files are processed and the generated results are returned to the client instead.In other words, ColdFusion files are never sent to the client, but what they create is. And depending on what a ColdFusion file contains, it likely will generate multiple different outputs all from that same single .cfm filethus the term template. ![]() |