ColdFusion Tutorial

ColdFusion Custom tags Example

How to make a CFMX Custom Tag and call it from a .cfm page for beginners
  • First, make sure you have your custom tags directory mapped. Login to your hosting control center and map the path to a folder you want to use to store your tags in.
  • Download the sample date custom tag. Download
  • The Date Tag has been downloaded times.
  • Unzip the file and save datetag.cfm to the folder you mapped for your custom tags.
  • Just add the tag shown below into the code of your page, make sure you don't add it as text on the page, add while in "code view". The page must be saved as a .cfm page so that the coldfusion application server will process it! OR
  • Last step: Copy/paste the sample code below and save it anywhere on your server. Note: you call the custom tag without the .cfm added onto it like this <CF_datetag>.
  • When you browse to the page on the server it will show the current date in the page.
  • This is just a simple example for learning. When you write code that will be re-used often you might consider making it a custom tag and just calling it everytime you need it. Other common ColdFusion Objects for handling re-used code are: <cfmodule> and <cfinclude>.
  • *If your hosting company does not allow you to map a ColdFusion Custom Tags folder, you will have to use <cfmodule> or <cfinclude>. I happen to like <cfmodule> and it gets processed very quickly.

Below is a live example of how it looks. Keep in mind you can format it with styles and color and make it look however you want, but we are keeping it bare bones for this custom tag tutorial. Also note, if you look in your browser code view, it only returns the results and you do not see and ColdFusion code in the page. The results are returned to the IIS web server from the Coldfusion Application server and served up on the web as html. Come back tomorrow and you will see the new date!


Custom Tags
What they do?
<CF_datetag> Example custom tag that inserts today's date into a .cfm page

Example for the date page is below.
The page name can be anything you want = anypagename.cfm

<title>cf tag counter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Note: You can stick the <CF_datetag> in a .cfm page all by itself, without any of the html code and it will still work just fine all by itself!

More ColdFusion Tutorials