SunQuest
 
       ColdFusion
  Home arrow ColdFusion arrow Page 7 - Introduction to ColdFusion Markup Language
IBM developerWorks
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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
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

Introduction to ColdFusion Markup Language
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2006-01-19

    Table of Contents:
  • Introduction to ColdFusion Markup Language
  • Tags Used in CFML
  • The Application.cfm File
  • Understanding Common ColdFusion Tags
  • The cfif tag
  • The cfswitch tag
  • The cflocation tag

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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.

    <cfinclude>

    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: 

      <html>
      <head>
        <title>Welcome</title>
      </head>
      <body>
        This is our header.<br />
        ----------<br />

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

        ----------<br />
        this is our footer.<br />
      </body>
      </html>
       
    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.

       · This article is an excerpt from the book "ColdFusion Web Development with...
     

    Buy this book now. This article is 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). Check it out today at your favorite bookstore. Buy this book now.

    COLDFUSION ARTICLES

    - 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...
    - My First Application on ColdFusion MX Server







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway