Componentizing the Web: ColdFusion 4 Custom Tags
ColdFusion 4.0 (now by Allaire!) is taking the enterprise world by storm. While PHP developers are struggling with include files and ASP developers are getting lost in "spaghetti" code, CFML developers have a secret weapon: <cf_customtag>.
Creating a Reusable Component
Instead of writing the same HTML table logic over and over, you can wrap it in a custom tag. Save a file as my_table.cfm in your customtags directory.
<!--- my_table.cfm --->
<cfif thisTag.executionMode is "start">
<table border="1" cellpadding="5">
<tr><th><cfoutput>#attributes.title#</cfoutput></th></tr>
<tr><td>
<cfelse>
</td></tr>
</table>
</cfif>
Using the Tag
Now, in your main page, you can call it just like a built-in ColdFusion tag.
<cf_my_table title="User List">
<ul>
<li>Admin</li>
<li>Editor</li>
<li>Viewer</li>
</ul>
</cf_my_table>
Why This is Revolutionary
Custom tags have access to the caller scope, meaning they can read and write variables in the page that called them. They can also have nested "child" tags. This is essentially "Web Components" fifteen years early.
If you're building a large-scale portal, stop thinking in pages and start thinking in tags. Your maintenance team will thank you when the client asks to change the border color on 500 different tables.
Aunimeda builds modern web frontends - from single-page applications to complex multi-locale sites.
Contact us to discuss your frontend project. See also: Web Development, Corporate Website Development