Using the new HTMLHelperProperty in MachII 1.8

I ran into a situation this week while working on a MachII project I’m doing with my brother that I’m sure many of you have encountered before. We have our view pages broken up into small chunks that we render inside a “pod-like” layout on the screen. Many of these view pages are using a one or more jQuery plugins (including cfUniform, DataTables and FancyBox) which need the main jQuery library to be included in the header to make them work correctly. We had been doing something like this in the top of each view that needed jQuery:

1
2
3
4
5
6
<cfsavecontent variable="jQueryInit">
     <script type="text/javascript" language="javascript"
         src="/javascript/jquery-1.3.2.min.js"></script>
</cfsavecontent>
 
<cfhtmlhead text="#jQueryInit#"></cfhtmlhead>

This worked perfectly fine for a while, right up until the point where we had two views in the same request that needed jQuery. If you put the above code in each of the view pages, then only some of your jQuery plugins work because the jQuery javascript file was getting loaded and instantiated multiple times–wiping out everything that had been configured previously.

Read More