2011
Zen Coding: A Faster Way to Write HTML And Tag-Based CFML in CFBuilder/CFEclipse
CFML , ColdFusion Builder , Miscellaneous , Web development 6 Comments »Zen Coding, in a nutshell, is a kind of coding shorthand primarily used to output HTML or XML code.ᅠ For example, the following line of Zen Coding:
div#page>ul>li*2>img.itemImg+a
...will produce this:
<div id="page">
<ul>
<li><img src="" alt="" class="itemImg" /><a href=""></a></li>
<li><img src="" alt="" class="itemImg" /><a href=""></a></li>
</ul>
</div>
If you compare the Zen Code to its output, you can see what the different parts of the Zen Code statement do. Assuming you know how you want to structure your HTML code, it's a pretty quick and easy way to generate the code you want with very little typing.
Having been recently reminded about Zen Coding, I decided to try out the latest version of the Zen Coding for Eclipse plugin and see if it would work in ColdFusion Builder 2.
The short answer: it does (and I imagine it works in CFEclipse as well). Once the plugin is installed, you can open your .cfm files in the regular editor window and use Zen Coding statements.
But then I discovered something I didn't expect: the Zen Coding plugin will convert even element names it doesn't recognize into matching start and end tags. In other words, even though it's not designed to be used with CFML tags, it can output them. Combine that fact with Zen Coding's support for adding attributes, and you can enter this line:
ul>cfloop[index=s][from=1][to=#ListLen(stateList)#]>li
...and hit the Tab key to get this:
<ul>
<cfloop index="s" from="1" to="#ListLen(stateList)#">
<li></li>
</cfloop>
</ul>
...Maybe not the best real-world example, but it demonstrates the possibilities.ᅠ And the plugin lets you define your own shorthand abbreviations, so instead of typing "cfoutput[query]" to get "<cfoutput query=''>", you could define an abbreviation like "cfoutq" that will generate the same code.
I think this could be a cool way to write display code, and I'm looking forward to trying it out in real coding situations.
Update:ᅠ I totally overlooked the link on the Github page to the documentation for the current Zen Coding syntax:ᅠ http://code.google.com/p/zen-coding/wiki/ZenHTMLSelectorsEn
Recent Comments