|
ColdFusion Home
Basic ColdFusionIntroductionColdFusion Installation ColdFusion Editors ColdFusion Syntax ColdFusion Includes ColdFusion Variables ColdFusion Variable Types ColdFusion If Statements ColdFusion Loops ColdFusion Datasource ColdFusion Database Queries ColdFusion Lists ColdFusion Arrays ColdFusion Redirect ColdFusion Debugging ColdFusion Error Handling Advanced ColdFusionColdFusion MailColdFusion Functions ColdFusion Components ColdFusion Web Services ColdFusion Upload File ColdFusion Read File ColdFusion Write File ColdFusion Append File ColdFusion Rename File ColdFusion Copy File ColdFusion Move File ColdFusion Delete File Cffile Parameters Using cffile Parameters ColdFusion FTP (cfftp) cfftp Cached Connections ColdFusion HTTP (cfhttp) ColdFusion Query of Queries ColdFusion Charts ColdFusion Summary ColdFusion AdminCF AdministratorCF Archive and Deploy CF Scheduled Tasks CF Mini Tutorial ColdFusion BooksColdFusion MX BibleMacromedia ColdFusion MX 7 Web Application Construction Kit |
ColdFusion Includes (cfinclude)If you've used other scripting environments such as ASP or even .shtml files, you would be familiar with the concept of "includes". An "include" is a file that is embedded, or "included" within another file. This can be very useful when you want multiple ColdFusion templates to share the same block of code. A typical example might be your website's header and footer. If your website has a consistent header and footer on every page, you could use an include file for each of these. ColdFusion provides the cfinclude tag for specifying included files. Tag SyntaxYou'll notice that the cfinclude tag doesn't have a closing tag - it just accepts an attribute value (the included filename).
Code ExampleA common use of ColdFusion includes is to output a consistent header and footer throughout each page of a website. In this example, we're going to create a basic ColdFusion template which uses the cfinclude tag to include two other files. File 1: index.cfm
File 2: header.cfm
File 3: footer.cfm
Once you've created all of the above files, open index.cfm in your browser. The page should contain the contents of header.cfm at the top, and footer.cfm at the bottom. Now create a fourth ColdFusion template as follows and open it in your browser. File 4: about.cfm
Because this template includes the same header and footer file, you will see the same header and footer when displayed in a browser. |
Need Website Content?
Get unique, quality digital content for your website.
|