A Path to No Where

We try to use good programming techniques at DDA. Code re-use is important and can be a time safer when making modifications in the future. If your header and footer are the same in all of your pages, you can use the cfinclude tag. First, by putting all of your header information in one file, and all of your footer information in another, then executing the cfinclude tag to bring in the contents of that file to the page where you want the information included. Another tag that could be used is the cfmofule tag, which has the capability of containing both the header and footer information in one file. In the file that is being called with the cfmodule, the top of the file has this <cfif thisTag.ExecutionMode is ‘start’> which then follows the header information followed by a <cfelse> statement then the footer information then closing the if statement with a </cfif>. In the file, using the cfmodule tag for the line that has <cfmodule template=””> would then include the header information and not include the footer information until the cfmodule tag is ended with </cfmodule>. Some other methods of including files are cffile and using custom tags.

It is important to know where you are relative to the root of the hostname and what the file path is when it comes to scripts being run and importing files, style sheets, javascript code, and images. A forward slash followed by a location and filename would be an absolute path from the hostname. When working with relative path, it looks for the file ‘relative’ to where it is being called. Two periods before a forward slash moves up a directory from the relative path. If, in Coldfusion, you are trying to get the location of an included file, use the function GetCurrentTemplatePath() which will display the full path including the filename being called. Using the function GetBaseTemplatePath() will display the file location including the filename of the original script calling the included file. The function GetDirectoryFromPath() will chop the file name off of the path just displaying the directory location.