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 4.  Controlling Program Flow

In this example, we will check the current time and then display an appropriate greeting based on the time of day.

  1. In your text editor, type the code shown in Listing 4.1, or you can open the Greeting.cfm file from the CompletedFiles\Examples\Step04 folder.

    Listing 4.1 Greeting.cfm

    <!--- File: Greeting.cfm Description: Demonstrate the use of <CFIF> Author: Created: ---> <HTML> <HEAD> <TITLE>Daily Greeting</TITLE> </HEAD> <BODY> <!--- Check if it is morning or afternoon and customize greeting Use the Now() function to get the current Date and time Use the Hour() function to isolate just the hour The Hour() function returns a value of 0 - 23 ---> <H2> <CFIF Hour(Now()) LT 12> Good morning, <CFELSE> Good afternoon, </CFIF> welcome to my site. </H2> <P>I am glad you could make it.</P> </BODY> </HTML>

  2. Save this file as Greeting.cfm in the Examples\Step04 folder.

  3. Browse to the file. You should see something similar to Figure 4.1.

    Figure 4.1. The Greeting.cfm display.

  4. Change your system time from a.m. to p.m. or vice versa.

  5. Refresh the page. The greeting should change.


    Team-Fly    
    Top
     

    Категории