ColdFusion MX: From Static to Dynamic in 10 Steps

Team-Fly    

ColdFusion® MX: From Static to Dynamic in 10 Steps

By Barry Moore

Table of Contents
Step 1.  The Basics

Let's put together everything we've learned and create our first ColdFusion template.

We want to accomplish the following:

  • Use <CFSET> to set the value of a variable

  • Use the Now() function to grab the current date/time

  • Use the DateFormat() function to format the date to our liking

  • Use <CFOUTPUT> to output the values of our variables and functions

  • Use <CFINCLUDE> to reuse some common code.

Let's get cracking. Try to create your own template or follow these steps:

  1. Open Homesite or your text editor of choice.

  2. Enter the following code or open the completed file from your CFMX10Steps folder. Completed example files can be found in the CompletedFiles\Examples\Step01 directory. For more information on downloading and installing the book's supporting files please see the Appendix.

    <!--- File: Description Author: Created: ---> <HTML> <HEAD> <TITLE>My First Template</TITLE> </HEAD> <!--- set the value of the FirstName variable to your name ---> <CFSET FirstName= "Barry"> <BODY> <CFOUTPUT> <H1>Welcome #FirstName#</H1> Today's date is: #DateFormat(Now(), "DD MMMM, YYYY")# </CFOUTPUT> <HR> <!--- include copyright information ---> <CFINCLUDE TEMPLATE="Copyright.htm"> </BODY> </HTML>

  3. Enter your own information in the opening comments and save the file to your CFMX10Steps\Examples\Step01 directory as MyFirstTemplate.cfm. The CFMX10Steps\Examples directory is your working directory, as we create examples throughout the book save them here in the appropriate subdirectory.

  4. Make sure your web server and ColdFusion services are running. For information on creating a virtual mapping to the Examples directory please see the Appendix.

  5. Open your browser and enter the URL for the template. For example, it might be something like http://localhost/Examples/Step01/MyFirstTemplate. cfm. You must use the URL; you cannot simply open the file in the browser.

  6. You should see something similar to the page shown in Figure 1.13.

    Figure 1.13. MyFirstTemplate. cfm browser output.

  7. If you do not see a similar page or receive some sort of error, double-check that your code matches the preceding example. Check carefully for quotation marks and pound signs. If you are still having trouble, jump ahead to the next section, "Troubleshooting."

NOTE

<CFSET> tags can be placed anywhere in your template. They do not have to go inside the <BODY> or <HTML> tags. However, any <CFOUTPUT> blocks usually follow the same rules that apply to normal HTML tag use.


    Team-Fly    
    Top
     

    Категории