Home arrow ColdFusion arrow Page 7 - Introduction to ColdFusion Markup Language

Introduction to ColdFusion Markup Language

If you want to get a good start on learning ColdFusion, look no further. This article covers a whole bunch of CFML tags and some basic functions. It is the first of two parts, and excerpted from chapter three of the book ColdFusion Web Development with Dreamweaver MX 2004, written by Jen and Peter deHaan et al. (Apress; ISBN: 1590592379).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 50
January 19, 2006
  1. · Introduction to ColdFusion Markup Language
  2. · Tags Used in CFML
  3. · The Application.cfm File
  4. · Understanding Common ColdFusion Tags
  5. · The cfif tag
  6. · The cfswitch tag
  7. · The cflocation tag

print this article

Introduction to ColdFusion Markup Language - The cflocation tag
(Page 7 of 7 )

You can use the<cflocation>tag to stop processing the current page and redirect to a new URL. It is very similar to using a meta refresh or a JavaScript redirection. No output is sent to the user's screen prior to the redirection, though any CFML code up to the<cflocation>is executed.

Try entering the following code into a new Document window in Dreamweaver:

<cflocation url="http://www.apress.com">

When you test the page in a browser window, you will notice it bounce automatically to whatever URL you specify. The<cflocation>tag is very useful in situations where you want to insert a record into a database and then redirect the user to a confirmation page, or else redirect the user to the next step in a wizard. It is also useful after inserting a new record into a database, because it can prevent the user from refreshing the action page and submitting duplicate data.


The<cfinclude>tag is a very useful tag because it allows you to include the contents of another file in the current page (essentially serving the same function as classic HTML server-side includes). For example, you could build header and footer files and then dynamically include them in each page of your site.

Using<cfinclude>eliminates having to copy and paste the HTML and/or CFML for the header and footer into every page; instead, you can centralize the code and make modifications in only one place. Let's look at an example.

  1. Create two new ColdFusion files, one namedheader.cfmand the other calledfooter.cfm,in thecfbooksite using Dreamweaver. Make sure that you save these two files in the same directory as theApplication.cfmandindex.cfmfiles that you created in the earlier examples.
  2. In theheader.cfmfile, enter the following code: 

      This is our header.<br />
      ----------<br />

  3. Then enter the following code in thefooter.cfmfile:

      ----------<br />
      this is our footer.<br />
  4. Clear the contents of theindex.cfmand type in the following code:

    I am the original page.<br /> 
  5. Create a new line at the beginning of theindex.cfmpage. The code you entered in step 4 should be on line 2 now. Next, select the CFML Basic tab in the Insert bar and click on the cfinclude button, as shown in Figure 3-7.

    After clicking on the button, the Tag Editor Cfinclude dialog box will open with a text field named Template and a Browse button to the right, as shown in Figure 3-8.

    Click on the Browse button and select theheader.cfmpage that we just created. After completing this step, click OK and OK again to insert this tag into theindex.cfmpage.

    Figure 3-7.   Using Dreameaver MX 2004 to insert a<cfinclude>tag into a web page


    Figure 3-8.   The<cfinclude>Tag Editor 
  6. Now use the same procedure to includefooter.cfmat the bottom of the page. Theindex.cfmfile should now look like the following:

    <cfinclude template="header.cfm">
    I am the original page.<br /> <cfinclude template="footer.com">

When you runindex.cfmin a web browser, you will see the output in Figure 3-9.

Figure 3-9. Our page output, as seen in Internet Explorer 6

You can see that theheader.cfmandfooter.cfmfiles are included in the index.cfm page, processed, and then output into the browser. You can use this technique to embed headers, footers, counters, menus, Flash movies, or pretty much any sort of web content you wish. Be aware that any code in an included file will be executed in the file doing the include as if it were coded right there in the file doing the include, which means that variable-name conflicts could result in undesirable behavior. It is also important to become familiar with relative paths if you aren't already familiar with them." ../" goes up one directory level and "directoryname/" goes down. Just like HTML<img>,<a>, and other tags, relative paths are a good way to specify files in other directories for inclusion. Later in this book, you will learn about CFMappings, which are another way to specify the location of files for inclusion.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- 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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


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