Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JamoCA/c2df9e845ef0da9cdf9b2f30aacedd4d to your computer and use it in GitHub Desktop.
Save JamoCA/c2df9e845ef0da9cdf9b2f30aacedd4d to your computer and use it in GitHub Desktop.
Example of defining a default set of variables, setting default values & identifying actual values for debugging or unit tests.
<!--- 2024-10-16
Example of defining a default set of ColdFusion scoped variables, setting default values & identifying actual values for debugging or unit tests.
Tweet: https://x.com/gamesover/status/1846590541833855413
--->
<cfscript>
// Define default scoped variables;
variable_config = [
["id": "attributes.promotionID", "value": ""]
,["id": "attributes.options", "value": ""]
,["id": "attributes.FilteredDateStart", "value": ""]
,["id": "attributes.FilteredDateEnd", "value": ""]
,["id": "attributes.Keyword", "value": ""]
,["id": "attributes.City", "value": ""]
,["id": "attributes.IDs", "value": ""]
,["id": "attributes.Category", "value": ""]
,["id": "attributes.ExcludeID", "value": ""]
,["id": "attributes.Sort", "value": ""]
,["id": "variables.isDetail", "value": false]
,["id": "variables.isFestival", "value": false]
,["id": "request.isPortal", "value": false]
,["id": "request.Categories", "value": {}]
];
// create "default" & "actual" collections of variables for debugging or unit testing
variable_default = [:];
variable_debug = [:];
for (thisParam in variable_config){
variable_default[thisParam.id] = thisParam.value;
cfparam(name=thisParam.id, default=thisParam.value);
variable_debug[thisParam.id] = structget(thisParam.id);
}
writedump(var=variable_config, label="configuration");
writedump(var=variable_default, label="default parameters");
writedump(var=variable_debug, label="actual parameters (debug)");
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment