ColdFusion
  Home arrow ColdFusion arrow Page 2 - Getting Started With ColdFusion Templates ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
COLDFUSION

Getting Started With ColdFusion Templates and Parameters
By: Jackie Kong
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2003-01-02

    Table of Contents:
  • Getting Started With ColdFusion Templates and Parameters
  • Getting Started With ColdFusion Templates
  • Passing Parameters Through the URL
  • Passing Parameters Through Forms
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Getting Started With ColdFusion Templates and Parameters - Getting Started With ColdFusion Templates


    (Page 2 of 5 )

    Create a new folder called learncf under your server's root folder. This root folder differs depending on the web server you are using:
    • IIS - c:\inetpub\wwwroot
    • PWS - c:\inetpub\wwwroot
    • Apache - c:\program files\apache group\apache\htdocs
    After everything is setup, open your favorite text editor such as Notepad or Ultraedit. Enter the following code listing and save the file as hello.cfm under your newly created folder:

    <html>
    <head>
    <title>Hello World</title>
    <head>

    <body bgcolor=ffffff>
    <center>
    <br><br><h1>Hello World!!</h1><hr>
    <b>Today's date is:</b><br>
    <cfoutput>
    <cfset today = now()>
    <i>#today#</i>
    </cfoutput>
    </center>
    </body>

    </html>


    View this file in your browser at http://localhost/learncf/home.cfm or http://127.0.0.1/learncf/home.cfm. Your page should look similar to this:



    ColdFusion tags and HTML tags are very similar. They both have beginning and end tags, and the end tag is preceded by a forward-slash (/). In the above example we used <cfoutput>. The <cfoutput> tag is used if you want to output ColdFusion data. Its syntax is as follows:

    <cfoutput>ColdFusion, HTML expressions</cfoutput>

    Another very useful tag that we used is <cfset>. The <cfset> tag is used to create and modify variables in ColdFusion. Its syntax is as follows:

    <cfset variable_name = variable_value>

    We created a variable called today using <cfset>, and assigned it the value of now(). Now() is actually a ColdFusion function that returns the current server's date and time. You display the value of a ColdFusion variable by enclosing the variable name in pound signs (#), just like we did with #today# in our example above.

    Let's go a bit further by formatting the date and time value to make it more user-friendly. Simply change the existing <cfset> statement to something like this:

    <html>
    <head>
    <title>Hello World</title>
    <head>

    <body bgcolor=ffffff>
    <center>
    <br><br><h1>Hello World!!</h1><hr>
    <b>Today's date is:</b><br>
    <cfoutput>
    <cfset today =
    DateFormat(now(), "dddd, mmmm d, yyyy")>
    <i>#today#</i>
    </cfoutput>
    </center>
    </body>

    </html>


    Save your file and reload your browser. We now have a human readable date and time:



    You might have already guessed that DateFormat is a ColdFusion function that formats any date you pass to it. Its syntax is as follows:

    DateFormat(date [,format mask])

    The format mask sets how ColdFusion should display the date, according to the following:
    • d: Day of the month as digits with no leading zero for single-digit days.
    • dd: Day of the month as digits with a leading zero for single-digit days.
    • ddd: Day of the week as a three-letter abbreviation.
    • dddd: Day of the week as its full name.
    • m: Month as digits with no leading zero for single-digit months.
    • mm: Month as digits with a leading zero for single-digit months.
    • mmm: Month as a three-letter abbreviation.
    • mmmm: Month as its full name.
    • y: Year as last two digits with no leading zero for years less than 10.
    • yy: Year as last two digits with a leading zero for years less than 10.
    • yyyy: Year represented by four digits.
    • gg: Period/era string. Currently ignored, but reserved for future use.
    Last but not least, comments can be added in ColdFusion by using <!--- ---> tags. These tags are very similar to those of HTML's <!-- and --> tags. The following code illustrates how to use a ColdFusion comment:

    <!---
    Author: Kongtechnology.com
    Purpose: My first ColdFusion template
    Date: 03/January/2003
    --->


    You can put the above comment into hello.cfm too:

    <html>
    <head>
    <title>Hello World</title>
    <head>

    <body bgcolor=ffffff>
    <center>
    <br><br><h1>Hello World!!</h1><hr>
    <b>Today's date is:</b><br>
    <cfoutput>

    <!---
    Author: Kongtechnology.com
    Purpose: My first ColdFusion template
    Date: 03/January/2003
    --->

    <cfset today =
    DateFormat(now(), "dddd, mmmm d, yyyy")>
    <i>#today#</i>
    </cfoutput>
    </center>
    </body>

    </html>


    Now that we know the basics of how a ColdFusion template works, let's see how we can pass parameters to our ColdFusion templates.

    More ColdFusion Articles
    More By Jackie Kong


       · In the first step (hello.cfm), after it's creation you ask us to test it in a...
     

    COLDFUSION ARTICLES

    - Adobe ColdFusion Just Got More RAD
    - How to Access a SQL Anywhere Database with C...
    - CFXML: Probing XMLDOM in ColdFusion
    - Creating a Web Service with ColdFusion: the ...
    - CFAjax: What it is and How to Use it
    - Querying SQL 2000 Server from ColdFusion
    - Introduction to ColdFusion Markup Language, ...
    - Introduction to ColdFusion Markup Language
    - Databases and Dreamweaver MX 2004, concluded
    - Databases and Dreamweaver MX 2004
    - Welcome to Coldfusion MX 6.1, concluded
    - Welcome to Coldfusion MX 6.1
    - What You Must Know About ColdFusion Flow-Con...
    - What You Must Know About Operators in ColdFu...
    - Everything You Must Know About ColdFusion Va...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT