A new part of ColdFusion our development team has been looking into more is the custom tags (cf_). Soon to be used with the Polar CMS (Visit official site), custom tags allow you to have scripts and coding within a tag that can be called from a cfm page as shown below:

<!— CFM Page (cfcustomtag_caller.cfm)—>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Call Tag</title>
</head>

<body>
<cf_cfcustomtag customVar=”test”>
<p>SOME HTML</p>

<cf_cfcustomtag form=”testFormCode”>
</body>
</html>

As you can see we are using a new tag <cf_cfcustomtag> with custom variables (customVar=”test”). These variables can be picked up within our custom tag cfm file we are about to create.

<!— CFM Page (cfcustomtag.cfm)—>
<cfoutput>
<cfif isDefined(“ATTRIBUTES.customVar”)>
<h1>#Now()#</h1>
<p>#ATTRIBUTES.customVar#</p>

</cfif>
<cfif isDefined(“ATTRIBUTES.form”)>
<p>#ATTRIBUTES.form#</p>
</cfif>
</cfoutput>

The above is a simple CFM file which has HTML and ColdFusion code. As you will notice we have named the file ‘cfcustomtag.cfm’ which is the same name as the tag: <cf_cfcustomtag> just without the cf_ at the start. Coldfusion will look for any files with the same naming tag.

You may ask why not use a <cfinclude> tag, but with cfincludes they can be slower and you are not able to reuse the cfinclude as easy as a cf_ custom tag. With custom tags you can lower the amount of code you need by using the extra variables (ATTRIBUTES).

Hope you enjoy using custom cf_ tags. Feel free to comment and add your code to show better ways of using cf_ tags. You may also want to research <cfmodule> tags.

Leave a Reply

Your email address will not be published. Required fields are marked *

About Host Media

We have been hosting websites since 2002 and are always moving forward. All articles written under the Host Media author are created by the team who support our customers.

Category

ColdFusion/Railo & MySQL

Tags

, , , ,