Wednesday, March 15, 2023
HomeColdFusionI have actually Never ever Had A Great Tale For View-Rendering Helpers...

I have actually Never ever Had A Great Tale For View-Rendering Helpers In ColdFusion

As I have actually been excavating right into the Hotwire structure, I have actually been taking a look at a great deal of Ruby on Bed Rails code (which is where Hotwire came from). Originating from a ColdFusion history, grokking Bed rails code is rather difficult due to the fact that it’s (apparently) like 99% “sight assistants” and also syntactic sugar. CFML, on the various other hand – with its impressive tag assistance and also encodeFor * works – really feels even more obtainable. Yet, recently in a Stimulus controller demonstration, I needed to compose this in a CFML theme:

<< switch.
data-action=" moms and dad ## logAction"
data-parent-child-id-param=" #encodeForHtmlAttribute( )#".
data-parent-child-data-param=" #encodeForHtmlAttribute( serializeJson( thing) )#">>.
Trigger Moms And Dad Activity.

It was the quality with the ingrained serializeJson() phone call that simply scrubed me the upside-down. Do not obtain me incorrect - I enjoy me an encodeForHtmlAttribute() phone call ( safety and security for the win!); yet, it's so verbose. As well as, with the serializeJson() contact top of it, it's excessive words!

I began to think of "sight assistants". As well as exactly how, after 20+ years of composing CFML, I have actually never ever actually had a great tale for view-related energies.

I recognize that some ColdFusion structures have means to "amazingly" make some Individual Specified Features (UDFs) offered to the sight making themes. As an example, Structure One (FW/1) reviews themes in the context of your Application.cfc part. Because of this, any type of approaches in stated part are offered in your sight themes.

Yet, this really feels a little bit untidy to me - having 2 various issues (application occasions and also arrangement + sight making) being taken care of by the very same part.

I have not made use of ColdBox, yet I have actually reviewed that if you have * Helper.cfm themes in unique areas, ColdBox will certainly make them offered for the pertinent sight making themes.

Yet, this additionally really feels a little bit also "enchanting" to me. Early in my job, I invested a great deal of time attempting to determine exactly how to hack UDFs to make them worldwide offered; just to, later on in my job, pertained to recognize exactly how enchanting it was to have specific code that was understandable.

A number of years earlier, I considered accumulating HTML course names utilizing an assistant feature. I ask yourself if I might take that idea, cover it in a ColdFusion part, and also simply expand it to make it extra durable. With a ColdFusion part as the product packaging, I might cache it and after that simply alias it (for brevity) where ever before it was demand.

Something similar to this - and also for this expedition, I'm simply thinking of qualities:

<< cfscript>>.

// In a manufacturing application, this ColdFusion part would certainly be cached in the application.
// range, or wired right into a dependency-injection device.
application.viewHelper = brand-new ViewHelper();.

// After that, I would likely alias it for brevity anywhere it was required.
sight = application.viewHelper;.

<. << cfoutput>>.



Most Popular

Recent Comments