Home arrow ColdFusion arrow Page 2 - Getting Started With ColdFusion Templates and Parameters
COLDFUSION

Getting Started With ColdFusion Templates and Parameters


Because ColdFusion is template driven, it's very easy to learn. In this article Jackie shows us how to construct our own ColdFusion templates. He also shows us how to work with both URL and form parameters.

Author Info:
By: Jackie Kong
Rating: 4 stars4 stars4 stars4 stars4 stars / 34
January 02, 2003
TABLE OF CONTENTS:
  1. · Getting Started With ColdFusion Templates and Parameters
  2. · Getting Started With ColdFusion Templates
  3. · Passing Parameters Through the URL
  4. · Passing Parameters Through Forms
  5. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.
blog comments powered by Disqus
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...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials