Creating Your First ColdFusion Page

I l @ ve RuBoard

Now that you know your way around ColdFusion Studio, it's time to put that knowledge to use and create your first ColdFusion Page. You won't be doing anything fancy this time around, just a very basic page. It has become something of a tradition that when learning a new programming language the first thing you do is output "Hello World!" You will be doing just that. OK, you probably wouldn't be putting that on your commercial Web site, but it's a good way of getting started, and makes you a member of the programmers' club.

  1. Choose File > New and select Default Template from the New Document window.

    A new default template appears. This template already has the basic tags for an HTML document built into it, so you do not have to worry about adding them.

    TIP

    You can also create a new default template by pressing Ctrl+N.

  2. Add the following code to the body of the document:

     <cfoutput>Hello World!</cfoutput> 

    The <cfoutput> tag in ColdFusion is one of its most important tools. Anything that is put between a set of <cfoutput> tags will be output by the ColdFusion server. It doesn't matter what is between those tags; whether it is plain HTML text or a ColdFusion variable, it's all handled by the ColdFusion server.

  3. Click File > Save and browse to C:\Inetpub\ wwwroot . Create a subfolder called lesson1.

    Where you save your files is very important. In order for you to be able to view your files in a browser you must save them in the Inetpub\wwwroot folder, or a subfolder of the Inetpub\wwwroot folder.

  4. Type helloworld.cfm into the File Name field and click Save.

    You have now created your first ColdFusion page. Now you'll see what it does.

    TIP

    You can also press Ctrl+S to save your ColdFusion files.

  5. Open a browser and type http://127.0.0.1/Lesson1/helloworld.cfm into the address field. Press Return.

    You should see "Hello World!" displayed in the browser.

  6. Click View > Source.

    If you're using Navigator, choose View > Page Source.

    As you can see, the <cfoutput> tags are gone. All that remains is "Hello World!" ColdFusion has taken the information between the <cfoutput> tags, processed it, and returned the corresponding HTML. This would look identical to the source if you had typed "Hello World!" without using the <cfoutput> tags. The big difference is the fact that, using the tags, you could change the variable value without having to change the HTML. For example, if you had a page with the name Kevin output in several places in plain HTML, you would have to change every instance of Kevin separately. If Kevin is a ColdFusion variable, all you'd have to do is change the value of the variable once and it is changed everywhere. You can see how this can be a big timesaver.

I l @ ve RuBoard


Macromedia ColdFusion 5. Training from the Source
Macromedia ColdFusion 5 Training from the Source (With CD-ROM)
ISBN: 0201758474
EAN: 2147483647
Year: 2002
Pages: 99
Authors: Kevin Schmidt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net