Skip to content

Instantly share code, notes, and snippets.

View bennadel's full-sized avatar
💭
Life's a garden, dig it!

Ben Nadel bennadel

💭
Life's a garden, dig it!
View GitHub Profile
@bennadel
bennadel / test.cfm
Created March 22, 2023 12:37
Russian Doll Content Wrapping With CFSaveContent In ColdFusion
<cfoutput>
<!--- Define the initial BODY content. --->
<cfsavecontent variable="body">
<p>
This is the body!
</p>
</cfsavecontent>
@bennadel
bennadel / babel.config.json
Last active April 23, 2023 12:57
Incrementally Applying Hotwire To An Existing ColdFusion Application
{
"plugins": [
"@babel/plugin-proposal-optional-chaining"
]
}
@bennadel
bennadel / ViewHelper.cfc
Created March 15, 2023 13:08
I've Never Had A Good Story For View-Rendering Helpers In ColdFusion
component
output = false
hint = "I provide utility methods for rendering HTML in a view template."
{
/**
* I output the given attribute with proper attribute encoding. If the value is a
* complex data structure, it is serialized as JSON.
*/
public string function attr(
@bennadel
bennadel / index.cfm
Created March 14, 2023 11:38
Using Nested Stimulus Controllers With Hotwire And Lucee CFML
<cfscript>
items = [
{ id: 1, name: "Item One" },
{ id: 2, name: "Item Two" },
{ id: 3, name: "Item Three" }
];
</cfscript>
<cfmodule template="./tags/page.cfm">
@bennadel
bennadel / a.cfm
Created March 13, 2023 10:43
Using "return" To Short-Circuit A CFML Template In ColdFusion
<cfscript>
writeOutput( "A-1 <br />" );
return;
writeOutput( "A-2 <br />" );
</cfscript>
@bennadel
bennadel / _create.cfm
Created March 12, 2023 16:45
Rendering A Fly-Out Form Panel Using Turbo Frames With Hotwire And Lucee CFML
<!---
When rendered as a top-level request, we can render the form AS-IS. However, if we're
rendering inside a Turbo Frame (ie, we're trancluding the form into another page), we
have to render the form inside a like-named Turbo Frame so that Hotwire can merge the
results back into the live page.
--
NOTE: In a more robust architecture, this could be implemented much more seamlessly as
a layout selection, such as a "standard" layout vs a "fly-out" layout. However, to
keep things as simple as possible, I'm rendering both types of layouts right here in
the same template so that we can see the mechanics at play.
@bennadel
bennadel / index.cfm
Created March 7, 2023 12:19
Styling Submit Buttons During Form Submission With Hotwire And Lucee CFML
<cfscript>
if ( request.isPost ) {
// Sleeping to give us time to observe the busy-state of the submit button.
sleep( 2000 );
location( url = "index.htm?signed=true", addToken = false );
}
@bennadel
bennadel / banner.cfm
Created March 4, 2023 15:06
Rendering A Persistent Dismissible Banner Using Hotwire And Lucee CFML
<cfscript>
param name="request.context.clearBanner" type="boolean" default=false;
if ( request.context.clearBanner ) {
application.bannerText = "";
// If this request is not being scoped to a Turbo Frame (ie, Turbo Drive has not
// yet taken over the page navigation), let's redirect the user back to the
@bennadel
bennadel / index.cfm
Created March 2, 2023 13:26
Dynamically Adding Stimulus Controllers To Static Content Using Hotwire And Lucee CFML
<cfmodule template="./tags/page.cfm">
<cfoutput>
<h2>
Welcome to My Site
</h2>
<div id="dyno">
This is static content.
</div>
@bennadel
bennadel / Application.cfc
Created March 1, 2023 14:02
Transcluding A Form Into A Turbo Frame Using Hotwire And Lucee CFML
component
output = false
hint = "I define the application settings and event handlers."
{
// ... truncated code ... //
/**
* I get called once to initialize the request.
*/