5 Cool New(er) Things in Mach-II
I’m not on the cutting edge of Mach-II features, but recently my company upgraded from Mach-II version 1.5 to 1.8. These are 5 (just to put a cap on it) features that I have found incredibly useful and cool.
Environment Property
The environment property has been especially useful for having different a urlBase for production servers. No longer do we have to quickly change our urlBase before committing our code, or mistakingly keep a local urlBase in our mach-ii.xml. It has been a blessing.
HTML Helper Property
I really enjoyed creating an asset package and easily controlling it inside of the mach-ii.xml. In addition, I could add meta information, JavaScript, and css to the page before my template and it would automagically be attached to the head of my template.
<cfset html.addMeta("title", event.getArg("contentTitle")) />
<cfset html.addCharset() />
<cfset html.addMeta("description", event.getArg("MetaDescription")) />
<cfset html.addMeta("keywords", event.getArg("MetaKeywords")) />
<cfset html.addAssetPackage("default") />
<cfset html.addLink("icon", "favicon.ico") />
<cfset html.addLink("rss", "/path/to/rssFeed.cfm") />
CopyToScope function
I was able to implement this early and often. It really removes a lot of clutter and confusion on my pages. Instead of numerous lines assigning variables to event args, it all gets completed in just one line. Especially helpful for my udf property, menu property, and the html property.
<cfset copyToScope("${properties.html},${properties.udf},${properties.menuProperty}") />
View Loaders
This was surprisingly simple to use. I removed all of my view-page xml nodes from the mach-ii.xml and replaced them with one line of code. It just worked, since I was already using that same dot notation to naming my views.
<page-views>
<view-loader type="MachII.framework.viewLoaders.PatternViewLoader" />
</page-views>
The Tag Library
This kind of goes along with the HTML Helper Property, but it’s cool enough to make it on the list by itself. I haven’t event used the form part of the tag library. Instead of going through the CDATA comment crap that usually has to happen to property create an inline script. Bam, done.
<view:script outputType="inline">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</view:script>
<view:script outputType="inline">
try {
var pageTracker = _gat._getTracker("UA-X");
pageTracker._trackPageview();
} catch(err) {}
</view:script>