Skip to content

Instantly share code, notes, and snippets.

@bennadel
Last active May 5, 2021 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennadel/afdce739f2bc6960da24410b9eab89b0 to your computer and use it in GitHub Desktop.
Save bennadel/afdce739f2bc6960da24410b9eab89b0 to your computer and use it in GitHub Desktop.
Validating And Documenting Complex Object Structures With CFParam In Lucee CFML 5.3.7.47
<cfscript>
// For safety and DOCUMENTATION (regarding which values are needed within this
// template), validate the general structure of the attributes.
param name="attributes.project" type="struct";
param name="attributes.project.id" type="numeric";
param name="attributes.project.name" type="string";
param name="attributes.project.createdAt" type="date";
param name="attributes.project.owner" type="struct";
param name="attributes.project.owner.id" type="numeric";
param name="attributes.project.owner.name" type="string";
param name="attributes.project.screens" type="array";
// We can't validate screen structures unless we have at least one screen.
if ( attributes.project.screens.len() ) {
param name="attributes.project.screens[ 1 ].id" type="numeric";
param name="attributes.project.screens[ 1 ].name" type="string";
param name="attributes.project.screens[ 1 ].clientFilename" type="string";
}
// .... consume attribute values ....
dump( attributes.project );
</cfscript>
<cfscript>
project = {
id: 1,
name: "Public Site Redesign",
createdAt: createDate( 2021, 1, 15 ),
owner: {
id: 4,
name: "Ben Nadel"
},
screens: [
{
id: 101,
name: "Home Page",
clientFilename: "home@2x.png"
}
]
};
module
template = "./MyTag.cfm"
project = project
;
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment