{"id":33227071,"url":"https://github.com/tonyjunkes/cfml-tags-to-cfscript","last_synced_at":"2026-01-05T21:01:55.908Z","repository":{"id":33750001,"uuid":"37405052","full_name":"tonyjunkes/cfml-tags-to-cfscript","owner":"tonyjunkes","description":"A collection of examples defining how to convert CFML code blocks written in tags to CFScript.","archived":false,"fork":false,"pushed_at":"2017-10-17T13:45:25.000Z","size":53,"stargazers_count":37,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-01-04T06:18:53.693Z","etag":null,"topics":["cfml","cfscript","coldfusion","lucee"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tonyjunkes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-14T08:31:50.000Z","updated_at":"2025-10-18T10:01:59.000Z","dependencies_parsed_at":"2022-07-31T11:08:02.403Z","dependency_job_id":null,"html_url":"https://github.com/tonyjunkes/cfml-tags-to-cfscript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tonyjunkes/cfml-tags-to-cfscript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyjunkes%2Fcfml-tags-to-cfscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyjunkes%2Fcfml-tags-to-cfscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyjunkes%2Fcfml-tags-to-cfscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyjunkes%2Fcfml-tags-to-cfscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonyjunkes","download_url":"https://codeload.github.com/tonyjunkes/cfml-tags-to-cfscript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyjunkes%2Fcfml-tags-to-cfscript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28218585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-05T02:00:06.358Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cfml","cfscript","coldfusion","lucee"],"created_at":"2025-11-16T16:00:53.798Z","updated_at":"2026-01-05T21:01:55.898Z","avatar_url":"https://github.com/tonyjunkes.png","language":null,"funding_links":[],"categories":["Documentation"],"sub_categories":[],"readme":"# CFML Tag to Script Conversions\n##### A collection of examples demonstrating the conversion of CFML code blocks written in tags to CFScript.\n\n**Currently a work in progress!**\n\n\u003e This is not the CFScript syntax documentation you're (possibly) looking for. That awesome piece of work, by Adam Cameron, can be found [here](https://github.com/adamcameron/cfscript) and is highly recommended as a reference to the content you'll find here.\n\u003e\n\u003e If you happen to be searching for a resource to learn CFML, check out [CFML in 100 Minutes](https://github.com/mhenke/CFML-in-100-minutes/wiki) by Mike Henke \u0026 [Learn CF in a Week](http://www.learncfinaweek.com/) by [this solid bunch of devs](http://www.learncfinaweek.com/contributors/).\n\nThe examples in this document are an attempt to demonstrate conversions of CFML tag-based code to script-based code as a way of learning / migrating to CFScript. It is assumed that you already have a relatively firm understanding of the ColdFusion Markup Language (at least on a tag-based level). For the sake of modernity, the converted examples will be written to comply (from an agnostic approach) with the most current versions of the various CFML engines at the time of writing - (ColdFusion 11, Railo 4.2 \u0026 Lucee 4.5).\n\n## Table of Contents\n1. [The Modern Implementation of Tags to Script](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#the-modern-implementation-of-tags-to-script)\n2. [Comments](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#comments)\n3. [Variables](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#variables)\n4. [Operators](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#operators)\n\t* [Decision](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#decision)\n\t* [Increment / Decrement](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#increment--decrement)\n\t* [Inline Assignment](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#inline-assignment)\n\t* [Boolean](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#boolean)\n\t* [Ternary \u0026 Null-Coalescing](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#ternary--null-coalescing)\n5. [Conditions](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#conditions)\n\t* [cfif / cfelseif / cfelse](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfif--cfelseif--cfelse)\n\t* [cfswitch](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfswitch)\n\t* [cftry / cfcatch / cffinally](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cftry--cfcatch--cffinally)\n\t* [cfthrow \u0026 cfrethrow](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfthrow--cfrethrow)\n6. [Iterations](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#iterations)\n\t* [General Purpose Loop](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#general-purpose-loop)\n\t* [Array Loop](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#array-loop)\n\t* [Struct Loop](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#struct-loop)\n\t* [List Loop](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#list-loop)\n\t* [Query Loop](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#query-loop)\n7. [Other Flow Control Tags](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#other-flow-control-tags)\n\t* [cfabort \u0026 cfexit](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfabort--cfexit)\n8. [General](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#general)\n\t* [cfoutput](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfoutput)\n\t* [cfsavecontent](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfsavecontent)\n\t* [cfthread](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfthread)\n\t* [cflock](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cflock)\n\t* [cfinclude](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfinclude)\n\t* [cflocation](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cflocation)\n9. [Debugging](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#debugging)\n\t* [cfdump](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfdump)\n\t* [cflog](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cflog)\n10. [Database](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#database)\n\t* [cfquery](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfquery)\n\t* [cftransaction](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cftransaction)\n11. [File System Operations](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#file-system-operations)\n\t* [cfdirectory](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfdirectory)\n\t* [cffile](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cffile)\n12. [Image Manipulation](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#image-manipulation)\n\t* [cfimage](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfimage)\n13. [Spreadsheet Integration](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#spreadsheet-integration)\n\t* [cfspreadsheet](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfspreadsheet)\n14. [Tags Implemented as Components](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#tags-implemented-as-components)\n\t* [cfquery / query.cfc](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfquery--querycfc)\n\t* [cfhttp / http.cfc](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfhttp--httpcfc)\n\t* [cfmail / mail.cfc](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfmail--mailcfc)\n\t* [cffeed / feed.cfc](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cffeed--feedcfc)\n\t* [cfftp / ftp.cfc](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfftp--ftpcfc)\n15. [Interfaces, Components \u0026 Functions](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#interfaces-components--functions)\n\t* [cfinterface](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfinterface)\n\t* [cfcomponent](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cfcomponent)\n\t* [cffunction](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#cffunction)\n\t* [A More Complete Component Example](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#a-more-complete-component-example)\n\t* [Annotations](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#annotations)\n\t* [Function Expressions](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#function-expressions)\n16. [Real World Conversions By Example](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#real-world-conversions-by-example)\n\t* [Example 1](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#example-1)\n\t* [Example 2](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#example-2)\n\t* [Example 3](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#example-3)\n17. [Tags Have Their Place](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#tags-have-their-place)\n\t* [Keeping Tags in the View](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#keeping-tags-in-the-view)\n\t* [Building Tag Code on the Script Side](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#building-tag-code-on-the-script-side)\n\n### The \u003cem\u003eModern\u003c/em\u003e Implementation of Tags to Script\n\nI want to open with this before diving into the depths of conversions. Adobe ColdFusion 11+, Railo 3.2+(?) and Lucee 4.5+ all offer some kind of full script syntax support (Railo \u0026 Lucee sharing the implementation) involving \u003cem\u003enear\u003c/em\u003e identical syntax between tag-base and script-base. Adobe ColdFusion 11 rolled it's own variation but Railo and Lucee both support ACF's syntax as of versions 4.2 and 4.5 respectively.\n\nAs per [Adam Cameron's CFScript Documentation](https://github.com/adamcameron/cfscript/blob/master/cfscript.md#the-rest):\n\u003e On Railo/Lucee this is a matter of removing the \"`\u003ccf`\" and the \"`\u003e`\", and using normal block syntax (curly braces) where the tag-version is a block-oriented tag.\n\n\u003e On ColdFusion, replace the \"`\u003ccftagname`\" with \"`cftagname(`\", and the \"`\u003e`\" with \"`)`\", and comma-separate the attributes. Note that this will make the construct look like a function, but it actually is not, and cannot be used like a function, eg this is invalid syntax:\n\n\u003e `result = cfhttp(method=\"post\", url=\"http://example.com\");`\n\nWhere the correct way would be: `cfhttp(result=\"result\", method=\"post\", url=\"http://example.com\");`\n\n### Comments\n\n_**Tags:**_\n```coldfusion\n\u003c!--- I'm a single-line comment. ---\u003e\n\n\u003c!---\nI'm a multi-\nline comment.\n---\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// I'm a single-line comment.\n// Notice that CFScript code within a \".cfm\" file must be wrapped in \u003ccfscript\u003e tags.\n\n/*\nI'm a multi-\nline comment.\n*/\n\n\u003c/cfscript\u003e\n```\n\n### Variables\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Some simple variable statements in tags ---\u003e\n\n\u003c!--- Default variable declarations ---\u003e\n\u003ccfparam name=\"title\" default=\"\"\u003e\n\u003ccfparam name=\"views\" type=\"numeric\" default=0\u003e\n\n\u003c!--- Regular assignment ---\u003e\n\u003ccfset title = \"Tags\"\u003e\n\u003ccfset views = 1\u003e\n\u003ccfset page = \"Title: #title#, Number: #views#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Some simple variable statements in script\n\n// Default variable declarations\nparam name=\"title\" default=\"\";\nparam name=\"views\" type=\"numeric\" default=0;\n\n// Regular assignment\ntitle = \"Script\";\nviews = 2;\npage = \"Title: #title#, Number: #views#\";\n// or\npage = \"Title: \" \u0026 title \u0026 \", \" \u0026 \"Number: \" \u0026 views;\n\n\u003c/cfscript\u003e\n```\n\n### Operators\n\n#### Decision\n\n_**Tags:**_\n```coldfusion\n\u003ccfset x = 1\u003e\n\u003ccfset y = [\n\tx EQ 1,\n\tx NEQ 1,\n\tx LT 1,\n\tx GT 1,\n\tx LTE 1,\n\tx GTE 1\n]\u003e\n\u003ccfdump var=\"#y#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// All tag based operators still work in script\n// There are also these equivalents\n\nx = 1;\ny = [\n\tx == 1,\n\tx != 1,\n\tx \u003c 1,\n\tx \u003e 1,\n\tx \u003c= 1,\n\tx \u003e= 1\n];\nwriteDump(y);\n\n\u003c/cfscript\u003e\n```\n\n#### Increment / Decrement\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Increment ---\u003e\n\u003ccfset x = 1\u003e\n\u003ccfset y = x++\u003e\n\u003ccfset z = ++x\u003e \u003c!--- or z = x + 1 ---\u003e\n\u003ccfdump var=\"#[x, y, z]#\"\u003e\n\n\u003c!--- Decrement ---\u003e\n\u003ccfset x = 1\u003e\n\u003ccfset a = x--\u003e\n\u003ccfset b = --x\u003e \u003c!--- or b = x - 1 ---\u003e\n\u003ccfdump var=\"#[a, b]#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Increment\nx = 1;\ny = x++;\nz = ++x // or z = x + 1\nwriteDump([x, y, z]);\n\n// Decrement\na = x--;\nb = --x // or b = x - 1\nwriteDump([a, b]);\n\n\u003c/cfscript\u003e\n```\n\n#### Inline Assignment\n\n_**Tags:**_\n```coldfusion\n\u003ccfset x = 0\u003e\n\u003ccfset y = \"string\"\u003e\n\n\u003ccfset x += 10\u003e\n\u003c!--- or x = x + 10 ---\u003e\n\u003ccfdump var=\"#x#\"\u003e\n\n\u003ccfset x -= 8\u003e\n\u003c!--- or x = x - 8 ---\u003e\n\u003ccfdump var=\"#x#\"\u003e\n\n\u003ccfset x /= 6\u003e\n\u003c!--- or x = x / 6 ---\u003e\n\u003ccfdump var=\"#x#\"\u003e\n\n\u003ccfset x *= 4\u003e\n\u003c!--- or x = x * 4 ---\u003e\n\u003ccfdump var=\"#x#\"\u003e\n\n\u003ccfset x %= 2\u003e\n\u003c!--- or x = x MOD 2 or x = x % 2 ---\u003e\n\u003ccfdump var=\"#x#\"\u003e\n\n\u003ccfset y \u0026= \"s\"\u003e\n\u003c!--- or y = y \u0026 \"s\" ---\u003e\n\u003ccfdump var=\"#y#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nx = 0;\ny = \"string\";\n\nx += 10;\n// or x = x + 10\nwriteDump(x);\n\nx -= 8;\n// or x = x - 8\nwriteDump(x);\n\nx /= 6;\n// or x = x / 6\nwriteDump(x);\n\nx *= 4;\n// or x = x * 4\nwriteDump(x);\n\nx %= 2;\n// or x = x MOD 2 or x = x % 2\nwriteDump(x);\n\ny \u0026= \"s\";\n// or y = y \u0026 \"s\"\nwriteDump(x);\n\n\u003c/cfscript\u003e\n```\n\n#### Boolean\n\n_**Tags:**_\n```coldfusion\n\u003ccfset x = y = 1\u003e\n\u003ccfset z = [\n\tNOT x,\n\tx EQ 1 AND y EQ 2,\n\tx EQ 1 OR y EQ 2\n]\u003e\n\u003ccfdump var=\"#z#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nx = y = 1;\nz = [\n\t!x,\n\tx == 1 \u0026\u0026 y == 2,\n\tx == 1 || y == 2\n];\nwriteDump(z);\n\n\u003c/cfscript\u003e\n```\n\n#### Ternary \u0026 Null-Coalescing\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Ternary ---\u003e\n\u003ccfset x = \"Tags\"\u003e\n\u003ccfset y = len(x) ? x : \"something else\"\u003e\n\u003ccfdump var=\"#y#\"\u003e\n\n\u003c!--- Null-Coalescing ---\u003e\n\u003ccfset y = z ?: \"something else\"\u003e\n\u003ccfdump var=\"#y#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Ternary\nx = \"CFScript\";\ny = len(x) ? x : \"something else\";\nwriteDump(y);\n\n// Null-Coalescing\ny = z ?: \"something else\";\nwriteDump(y);\n\n\u003c/cfscript\u003e\n```\n\n### Conditions\n\n#### cfif / cfelseif / cfelse\n\n_**Tags:**_\n```coldfusion\n\u003ccfset count = 10\u003e\n\u003ccfif count GT 20\u003e\n\t\u003ccfoutput\u003e#count#\u003c/cfoutput\u003e\n\u003ccfelseif count EQ 8\u003e\n\t\u003ccfoutput\u003e#count#\u003c/cfoutput\u003e\n\u003ccfelse\u003e\n\t\u003ccfoutput\u003e#count#\u003c/cfoutput\u003e\n\u003c/cfif\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\ncount = 10;\nif (count \u003e 20) {\n\twriteOutput(count);\n} else if (count == 8) {\n\twriteOutput(count);\n} else {\n\twriteOutput(count);\n}\n\n\u003c/cfscript\u003e\n```\n\n#### cfswitch\n\n_**Tags:**_\n```coldfusion\n\u003ccfset fruit = \"\"\u003e\n\u003ccfswitch expression=\"#fruit#\"\u003e\n    \u003ccfcase value=\"Apple\"\u003e\n        \u003ccfoutput\u003eI like apples!\u003c/cfoutput\u003e\n    \u003c/cfcase\u003e\n    \u003ccfcase value=\"Orange\"\u003e\n        \u003ccfoutput\u003eI like oranges!\u003c/cfoutput\u003e\n    \u003c/cfcase\u003e\n    \u003ccfcase value=\"Kiwi\"\u003e\n        \u003ccfoutput\u003eI like kiwi!\u003c/cfoutput\u003e\n    \u003c/cfcase\u003e\n    \u003ccfdefaultcase\u003e\n        \u003ccfoutput\u003eFruit, what fruit?\u003c/cfoutput\u003e\n    \u003c/cfdefaultcase\u003e\n\u003c/cfswitch\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nfruit = \"\";\nswitch(fruit) {\n\tcase \"Apple\":\n\t\twriteOutput(\"I like apples!\");\n\tbreak;\n\tcase \"Orange\":\n\t\twriteOutput(\"I like oranges!\");\n\tbreak;\n\tcase \"Kiwi\":\n\t\twriteOutput(\"I like kiwi!\");\n\tbreak;\n\tdefault:\n\t\twriteOutput(\"Fruit, what fruit?\");\n\tbreak;\n}\n\n\u003c/cfscript\u003e\n```\n\n#### cftry / cfcatch / cffinally\n\n_**Tags:**_\n```coldfusion\n\u003ccftry\u003e\n\t\u003ccfset x = y + z\u003e\n\t\u003ccfcatch type=\"any\"\u003e\n\t\t\u003ccfoutput\u003e#cfcatch.message#\u003c/cfoutput\u003e\n\t\u003c/cfcatch\u003e\n\t\u003ccffinally\u003e\n\t\t\u003ccfoutput\u003eFinally at the end.\u003c/cfoutput\u003e\n\t\u003c/cffinally\u003e\n\u003c/cftry\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\ntry {\n\tx = y + z;\n}\ncatch(any e) {\n\twriteOutput(e.message);\n}\nfinally {\n\twriteOutput(\"Finally at the end\");\n}\n\n\u003c/cfscript\u003e\n```\n\n#### cfthrow \u0026 cfrethrow\n\n_**Tags:**_\n```coldfusion\n\u003c!--- \u003ccfthrow\u003e ---\u003e\n\u003ccfthrow message=\"Oh no an error!!1\" type=\"RealBadErrorException\" detail=\"Something bad happened in detail\"\u003e\n\n\u003c!--- \u003ccfrethrow\u003e ---\u003e\n\u003ccfrethrow\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// \u003ccfthrow\u003e\nthrow(message = \"Oh no an error!!1\", type = \"RealBadErrorException\", detail = \"Something bad happened in detail\");\n// throw() can even be as simple as this...\nthrow \"Oh no an error!!1\";\n\n// \u003ccfrethrow\u003e\nrethrow;\n\n\u003c/cfscript\u003e\n```\n\n### Iterations\n\n#### General Purpose Loop\n\n_**Tags:**_\n```coldfusion\n\u003ccfloop index=\"i\" from=\"1\" to=\"10\"\u003e\n\t\u003ccfoutput\u003e#i#\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nfor (i = 1; i \u003c= 10; i++) {\n\twriteOutput(i);\n}\n\n\u003c/cfscript\u003e\n```\n\n#### Array Loop\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Define our array ---\u003e\n\u003ccfset myArray = [\"a\", \"b\", \"c\"]\u003e\n\n\u003c!--- By index ---\u003e\n\u003ccfloop index=\"i\" from=\"1\" to=\"#arrayLen(myArray)#\"\u003e\n\t\u003ccfoutput\u003e#myArray[i]#\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n\n\u003c!--- By array ---\u003e\n\u003ccfloop index=\"currentIndex\" array=\"#myArray#\"\u003e\n\t\u003ccfoutput\u003e#currentIndex#\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Define our array\nmyArray = [\"a\", \"b\", \"c\"];\n\n// By index\n// Note the use of the newer member function syntax for arrayLen()\nfor (i = 1; i \u003c= myArray.len(); i++) {\n\twriteOutput(myArray[i]);\n}\n\n// By array\nfor (currentIndex in myArray) {\n\twriteOutput(currentIndex);\n}\n\n// By arrayEach()\nmyArray.each(function(element, index) {\n\twriteOuput(element \u0026 \" : \" \u0026 index);\n});\n\n\u003c/cfscript\u003e\n```\n\n#### Struct Loop\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Define our struct ---\u003e\n\u003ccfset myStruct = {name: \"Tony\", state: \"Florida\"}\u003e\n\n\u003c!--- By struct ---\u003e\n\u003ccfloop item=\"currentKey\" collection=\"#myStruct#\"\u003e\n\t\u003ccfoutput\u003e\u003cli\u003e#currentKey# : #myStruct[currentKey]#\u003c/li\u003e\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Define our struct\nmyStruct = {name: \"Tony\", state: \"Florida\"};\n\n// By struct\nfor (currentKey in myStruct) {\n\twriteOutput(\"\u003cli\u003e#currentKey# : #myStruct[currentKey]#\u003c/li\u003e\");\n}\n\n// By structEach()\nmyStruct.each(function(key, value) {\n\twriteOutput(\"\u003cli\u003e#key# : #value#\u003c/li\u003e\");\n});\n\n\u003c/cfscript\u003e\n```\n\n#### List Loop\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Define our list ---\u003e\n\u003ccfset myList = \"a, b, c\"\u003e\n\n\u003c!--- By list ---\u003e\n\u003ccfloop index=\"item\" list=\"#myList#\"\u003e\n\t\u003ccfoutput\u003e#item#\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n\n\u003c!--- By array ---\u003e\n\u003ccfloop index=\"currentIndex\" array=\"#listToArray(myList, \",\")#\"\u003e\n\t\u003ccfoutput\u003e#currentIndex#\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Define our list\nmyList = \"a, b, c\";\n\n// By array\nfor (item in listToArray(myList, \",\")) {\n\twriteOutput(item);\n}\n\n// By listEach()\nmyList.each(function(element, index) {\n\twriteOuput(element \u0026 \" : \" \u0026 index);\n}, \",\");\n\n\u003c/cfscript\u003e\n```\n\n#### Query Loop\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Define our query ---\u003e\n\u003ccfset platform = [\"Adobe ColdFusion\", \"Railo\", \"Lucee\"]\u003e\n\u003ccfset myQuery = queryNew(\"\")\u003e\n\u003ccfset queryAddColumn(myQuery, \"platform\", \"CF_SQL_VARCHAR\", platform)\u003e\n\n\u003c!--- By row index ---\u003e\n\u003ccfloop index=\"i\" from=\"1\" to=\"#myQuery.recordCount#\"\u003e\n\t\u003ccfoutput\u003e\u003cli\u003e#myQuery[\"platform\"][i]#\u003c/li\u003e\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n\n\u003c!--- By group ---\u003e\n\u003ccfloop query=\"myQuery\" group=\"platform\"\u003e\n\t\u003ccfoutput\u003e\u003cli\u003e#platform#\u003c/li\u003e\u003c/cfoutput\u003e\n\u003c/cfloop\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Define our query\nplatform = [\"Adobe ColdFusion\", \"Railo\", \"Lucee\"];\nmyQuery = queryNew(\"\");\nqueryAddColumn(myQuery, \"platform\", \"CF_SQL_VARCHAR\", platform);\n\n// By row index\nfor (i = 1; i \u003c= myQuery.recordCount; i++) {\n    writeOutput(\"\u003cli\u003e#myQuery[\"platform\"][i]#\u003c/li\u003e\");\n}\n\n// By query\nfor (row in myQuery) {\n    writeOutput(\"\u003cli\u003e#row.platform#\u003c/li\u003e\");\n}\n\n\u003c/cfscript\u003e\n```\n\n### Other Flow Control Tags\n\n#### cfabort \u0026 cfexit\n\n_**Tags:**_\n```coldfusion\n\u003c!--- \u003ccfabort\u003e ---\u003e\n\u003ccfabort statusError=\"My error message\"\u003e\n\n\u003c!--- \u003ccfexit\u003e ---\u003e\n\u003ccfexit method=\"method\"\u003e\n```\n\n### General\n\n#### cfoutput\n\n_**Tags:**_\n```coldfusion\n\u003ccfoutput\u003eSome text and a #variable#\u003c/cfoutput\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nwriteOutput(\"Some text and a #variable#\");\n// or\nwriteOutput(\"Some text and a \" \u0026 variable);\n\n\u003c/cfscript\u003e\n```\n\n#### cfsavecontent\n\n_**Tags:**_\n```coldfusion\n\u003ccfsavecontent variable=\"myContent\"\u003e\n\t\u003ccfoutput\u003eSome content.\u003c/cfoutput\u003e\n\u003c/cfsavecontent\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nsavecontent variable=\"myContent\" {\n\twriteOutput(\"Some content.\");\n}\n\n\u003c/cfscript\u003e\n```\n\n#### cfthread\n\n_**Tags:**_\n```coldfusion\n\u003ccfthread action=\"run\" name=\"myThread\"\u003e\n\t\u003c!--- Do single thread stuff ---\u003e\n\u003c/cfthread\u003e\n\n\u003ccfthread action=\"join\" name=\"myThread,myOtherThread\" /\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nthread action=\"run\" name=\"myThread\" {\n\t// do single thread stuff\n}\n\nthread action=\"join\" name=\"myThread,myOtherThread\";\n\n\u003c/cfscript\u003e\n```\n\n#### cflock\n\n_**Tags:**_\n```coldfusion\n\u003ccflock timeout=\"60\" scope=\"session\" type=\"exclusive\"\u003e\n\t\u003ccfset session.myVar = \"Hello\"\u003e\n\u003c/cflock\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nlock timeout=\"60\" scope=\"session\" type=\"exclusive\" {\n\tsession.myVar = \"Hello\";\n}\n\n\u003c/cfscript\u003e\n```\n\n#### cfinclude\n\n_**Tags:**_\n```coldfusion\n\u003ccfinclude template=\"mypage.cfm\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\ninclude \"mypage.cfm\";\n\n\u003c/cfscript\u003e\n```\n\n#### cflocation\n\n_**Tags:**_\n```coldfusion\n\u003ccflocation url=\"mypage.cfm\" addToken=\"false\" statusCode=\"301\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nlocation(\"mypage.cfm\", \"false\", \"301\");\n\n\u003c/cfscript\u003e\n```\n\n### Debugging\n\n#### cfdump\n\n_**Tags:**_\n```coldfusion\n\u003ccfdump var=\"#cgi#\" label=\"CGI Scope\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nwriteDump(var = cgi, label = \"CGI Scope\");\n\n\u003c/cfscript\u003e\n```\n\n#### cflog\n\n_**Tags:**_\n```coldfusion\n\u003ccflog text=\"Logging some info.\" type=\"information\" application=\"no\" file=\"myLogFile\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nwriteLog(text = \"Logging some info.\", type = \"information\", application = \"no\", file = \"myLogFile\");\n\n\u003c/cfscript\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// \u003ccfabort\u003e\nabort \"My error message\";\n\n// \u003ccfexit\u003e\nexit \"method\";\n\n\u003c/cfscript\u003e\n```\n\n### Database\n\n#### cfquery\n\n_**Tags:**_\n```coldfusion\n\u003ccfquery name=\"myQuery\" datasource=\"myDSN\"\u003e\n\tSELECT myCol1, myCol2 FROM myTable\n\tWHERE myCol1 = \u003ccfqueryparam value=\"#myId#\" cfsqlype=\"cf_sql_integer\"\u003e\n\tORDER BY myCol1 ASC\n\u003c/cfquery\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Also see the \"Tags Implemented as Components\" section for another method of using \u003ccfquery\u003e in script\n\nmyQuery = queryExecute(\n\t\"SELECT myCol1, myCol2 FROM myTable\n\tWHERE myCol1 = :myId\n\tORDER BY myCol1 ASC\",\n\t{myId: {value: 5, cfsqltype: \"cf_sql_integer\"}},\n\t{datasource = \"myDSN\"}\n);\n\n\u003c/cfscript\u003e\n```\n\n#### cftransaction\n\n_**Tags:**_\n```coldfusion\n\u003ccftransaction\u003e\n\u003ccftry\u003e\n\t\u003c!--- code to run ---\u003e\n\t\u003ccftransaction action=\"commit\" /\u003e\n\t\u003ccfcatch type=\"any\"\u003e\n\t\t\u003ccftransaction action=\"rollback\" /\u003e\n\t\u003c/cfcatch\u003e\n\u003c/cftry\u003e\n\u003c/cftransaction\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\ntransaction {\n\ttry {\n\t\t// code to run\n\t\ttransaction action=\"commit\";\n\t}\n\tcatch(any e) {\n\t\ttransaction action=\"rollback\";\n\t}\n}\n\n\u003c/cfscript\u003e\n```\n\n### File System Operations\n\n#### cfdirectory\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Directory List ---\u003e\n\u003ccfdirectory action=\"list\" directory=\"#expandPath(\"./\")#\" recurse=\"false\" name=\"myList\"\u003e\n\n\u003c!--- Directory Create ---\u003e\n\u003ccfdirectory action=\"create\" directory=\"#expandPath(\"./new_directory\")#\"\u003e\n\n\u003c!--- Directory Delete ---\u003e\n\u003ccfdirectory action=\"delete\" directory=\"#expandPath(\"./my_directory\")#\"\u003e\n\n\u003c!--- Directory Rename ---\u003e\n\u003ccfdirectory action=\"rename\" directory=\"#expandPath(\"./my_directory\")#\" newdirectory=\"#expandPath(\"./new_directory\")#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Directory List\nmyList = directoryList(expandPath(\"./\"), false, \"query\");\n\n// Directory Create\ndirectoryCreate(expandPath(\"./new_directory\"));\n\n// Directory Delete\ndirectoryDelete(expandPath(\"./my_directory\"));\n\n// Directory Rename\ndirectoryRename(expandPath(\"./my_directory\"), expandPath(\"./new_driectory\"));\n\n\u003c/cfscript\u003e\n```\n\n#### cffile\n\n_**Tags:**_\n```coldfusion\n\u003c!--- File Write ---\u003e\n\u003ccffile action=\"write\" file=\"#expandPath(\"./myFile.txt\")#\" output=\"Here's some content for my file.\"\u003e\n\n\u003c!--- File Append ---\u003e\n\u003ccffile action=\"append\" file=\"#expandPath(\"./myFile.txt\")#\" attributes=\"normal\" output=\"Here's some new content.\"\u003e\n\n\u003c!--- File Read ---\u003e\n\u003ccffile action=\"read\" file=\"#expandPath(\"./myFile.txt\")#\" variable=\"myFile\"\u003e\n\n\u003c!--- File Read Binary ---\u003e\n\u003ccffile action=\"readBinary\" file=\"#expandPath(\"./myImage.jpg\")#\" variable=\"myImageBinary\"\u003e\n\n\u003c!--- File Rename ---\u003e\n\u003ccffile action=\"rename\" source=\"#expandPath(\"./myFile.txt\")#\" destination=\"#expandPath(\"./myNewFileName.txt\")#\" attributes=\"normal\"\u003e\n\n\u003c!--- File Copy ---\u003e\n\u003ccffile action=\"copy\" source=\"#expandPath(\"./myFile.txt\")#\" destination=\"#expandPath(\"./some/other/path\")#\"\u003e\n\n\u003c!--- File Move ---\u003e\n\u003ccffile action=\"move\" source=\"#expandPath(\"./myFile.txt\")#\" destination=\"#expandPath(\"./some/other/path\")#\"\u003e\n\n\u003c!--- File Delete ---\u003e\n\u003ccffile action=\"delete\" file=\"#expandPath(\"./myFile.txt\")#\"\u003e\n\n\u003c!--- File Upload ---\u003e\n\u003ccffile action=\"upload\" destination=\"#expandPath(\"./destination)#\" filefield=\"form.myFile\" nameconflict=\"makeunique\"\u003e\n\n\u003c!--- File Upload All ---\u003e\n\u003ccffile action=\"uploadall\" destination=\"#expandPath(\"./destination\")#\" nameconflict=\"makeunique\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// File Write\nfileWrite(expandPath(\"./myFile.txt\"), \"Here's some content for my file.\");\n\n// File Append\n// There is no \"fileAppend()\" so we access the file and use fileWriteLine()\nmyFile = fileOpen(expandPath(\"./myFile.txt\"), \"write\");\nfileWriteLine(myFile, \"Here's some new content.\");\nfileClose(myFile);\n\n// File Read\nmyFile = fileRead(expandPath(\"./myFile.txt\"));\n\n// File Read Binary\nmyImageBinary = fileReadBinary(expandPath(\"./myImage.jpg\"));\n\n// File Rename\n// Since there is no \"fileRename()\", fileMove() works just as well\nfileMove(expandPath(\"./myFile.txt\"), expandPath(\"./myNewFileName.txt\"));\n\n// File Copy\nfileCopy(expandPath(\"./myFile.txt\"), expandPath(\"./some/other/path\"));\n\n// File Move\nfileMove(expandPath(\"./myFile.txt\"), expandPath(\"./some/other/path\"));\n\n// File Delete\nfileDelete(expandPath(\"./myFile.txt\"));\n\n// File Upload\nfileUpload(expandPath(\"./destination\"), form.myFile, \"\", \"makeunique\");\n\n// File Upload All\nfileUploadAll(expandPath(\"./destination\"), \"\", \"makeunique\");\n\n\u003c/cfscript\u003e\n```\n\n### Image Manipulation\n\n#### cfimage\n\n\u003e There is \u003cem\u003equite\u003c/em\u003e the lot of image-related functions for \u0026lt;cfimage\u0026gt; that are already decently documented by Adobe. For the sake of avoiding a lengthy bit of repeating, you can check out those functions here - [ColdFusion Wiki: Image Functions](https://wikidocs.adobe.com/wiki/display/coldfusionen/Image+functions)\n\n### Spreadsheet Integration\n\n#### cfspreadsheet\n\n\u003e Much like \u0026lt;cfimage\u0026gt;, \u0026lt;cfspreadsheet\u0026gt; has a fair collection of functions for working with spreadsheets which you can find here - [ColdFusion Wiki: Microsoft Office Integration Functions](https://wikidocs.adobe.com/wiki/display/coldfusionen/Microsoft+office+integration+functions)\n\n### Tags Implemented as Components\n\n\u003e Note: If you are using ColdFusion 11+, (highly) consider using the script versions over the CFC implementations for example: `cfhttp(result=\"result\", method=\"post\", url=\"http://mydomain.com\");` over `Http.cfc` and `queryExecute()` over `Query.cfc`.\n\n#### cfquery / query.cfc\n\n_**Tags:**_\n```coldfusion\n\u003ccfquery name=\"myQuery\" datasource=\"myDSN\"\u003e\n\tSELECT myCol1, myCol2 FROM myTable\n\tWHERE myCol1=\u003ccfqueryparam value=\"#myId#\" cfsqlype=\"cf_sql_integer\"\u003e\n\tORDER BY myCol1 ASC\n\u003c/cfquery\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nmyQuery = new Query().setDatasource(\"myDSN\");\nmyQuery.setSQL(\"\n\tSELECT myCol1, myCol2 FROM myTable\n\tWHERE myCol1=:myId\n\tORDER BY myCol1 ASC\n\");\nmyQuery.addParam(name: \"myCol1\", value: \"#myId#\", cfsqltype: \"cf_sql_integer\");\nmyQuery = myQuery.execute().getResult();\n\n\u003c/cfscript\u003e\n```\n\n#### cfhttp / http.cfc\n\n_**Tags:**_\n```coldfusion\n\u003ccfhttp result=\"result\" method=\"GET\" charset=\"utf-8\" url=\"https://www.google.com/\"\u003e\n\t\u003ccfhttpparam name=\"q\" type=\"formfield\" value=\"cfml\"\u003e\n\u003c/cfhttp\u003e\n\n\u003ccfdump var=\"#result#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nhttpService = new http(method = \"GET\", charset = \"utf-8\", url = \"https://www.google.com/\");\nhttpService.addParam(name = \"q\", type = \"formfield\", value = \"cfml\");\nresult = httpService.send().getPrefix();\n\nwriteDump(result);\n\n\u003c/cfscript\u003e\n```\n\n#### cfmail / mail.cfc\n\n_**Tags:**_\n```coldfusion\n\u003ccfmail to=\"your@email.com\" from=\"another@email.com\" subject=\"CFMail Example\"\u003e\n\tYour Email Message!!1\n\u003c/cfmail\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// It's a good idea to build your message inside a save content block first\nsavecontent variable=\"mailBody\" {\n\twriteOutput(\"Your Email Message!!1\");\n};\n// Create and populate the mail object\nmailService = new mail(\n\tto = \"your@email.com\",\n\tfrom = \"another@email.com\",\n\tsubject = \"CFMail Example\",\n\tbody = mailBody\n);\n// Send\nmailService.send();\n\n\u003c/cfscript\u003e\n```\n\n#### cffeed / feed.cfc\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Read ---\u003e\n\u003ccffeed\n\tname=\"feed\"\n\taction=\"read\"\n\tsource=\"http://feeds.feedburner.com/ColdfusionbloggersorgFeed?format=xml\"\n\tquery=\"feedQuery\"\n\tproperties=\"feedMetadata\"\n\u003e\n\u003ccfdump var=\"#feed#\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Read\nfeedService = new feed();\nfeed = feedService.read(\n\tsource = \"http://feeds.feedburner.com/ColdfusionbloggersorgFeed?format=xml\",\n\tquery = \"feedQuery\",\n\tproperties = \"feedMetadata\"\n);\nwriteDump(feed);\n\n\u003c/cfscript\u003e\n```\n\n#### cfftp / ftp.cfc\n\n_**Tags:**_\n```coldfusion\n\u003c!--- Open connection ---\u003e\n\u003ccfftp action=\"open\" connection=\"myConn\" username=\"myUName\" password=\"myPW\" server=\"ftp.server.com\" stopOnError=\"true\"\u003e\n\u003c!--- Get list of dir ---\u003e\n\u003ccfftp action=\"listdir\" connection=\"myConn\" name=\"filesList\" directory=\"/\" stopOnError=\"true\"\u003e\n\u003c!--- Close connection ---\u003e\n\u003ccfftp action=\"close\" connection=\"myConn\" stopOnError=\"true\"\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n// Create FTP service and set attributes for connection\nftpService = new ftp(); \nftpService.setConnection(\"myConn\");\nftpService.setUsername(\"myUName\");\nftpService.setPassword(\"myPW\");\nftpService.setServer(\"ftp.server.com\");\nftpService.setStopOnError(true);\n// Open connection\nftpService.open();\n// Get list of dir\nfileList = ftpService.listdir(directory = \"/\", stopOnError = true).getResult();\n// Close connection\nftpService.close();\n\n\u003c/cfscript\u003e\n```\n\n### Interfaces, Components \u0026 Functions\n\n#### cfinterface\n\n_**Tags:**_\n```coldfusion\n\u003ccfinterface displayname=\"My Interface\"\u003e\n\t\u003ccfunction name=\"myFunction\" returntype=\"numeric\"\u003e\n\t\t\u003ccfargument required=\"true\" type=\"string\" name=\"myArgument\"\u003e\n\t\u003c/cffunction\u003e\n\u003c/cfinterface\u003e\n```\n\n_**Script:**_\n```coldfusion-cfc\ninterface displayname=\"My Interface\" {\n\tnumeric function myFunction(required string myArgument);\n}\n```\n\n#### cfcomponent\n\n_**Tags:**_\n```coldfusion\n\u003ccfcomponent displayname=\"myComponent\" output=\"false\"\u003e\n\t\u003c!--- functions and other values here ---\u003e\n\u003c/cfcomponent\u003e\n```\n\n_**Script:**_\n```coldfusion-cfc\ncomponent displayname=\"myComponent\" output=\"false\" {\n\t// functions and other values here\n}\n```\n\n#### cffunction\n\n_**Tags:**_\n```coldfusion\n\u003ccffunction access=\"public\" returntype=\"boolean\" name=\"myFunction\"\u003e\n\t\u003ccfargument required=\"true\" type=\"any\" name=\"myArgument\"\u003e\n\t\n\t\u003c!--- Some function bits ---\u003e\n\t\n\t\u003ccfreturn true\u003e\n\u003c/cffunction\u003e\n```\n\n_**Script:**_\n```coldfusion-cfc\npublic boolean function myFunction(required any myArgument) {\n\t// Some function bits\n\t\n\treturn true;\n}\n```\n\n#### A More Complete Component Example\n\n_**Tags:**_\n```coldfusion\n\u003ccfcomponent displayname=\"Utils\" output=\"false\"\u003e\n\t\u003ccfproperty name=\"version\" type=\"string\" default=\"0.0.1\"\u003e\n\n\t\u003ccffunction access=\"public\" returntype=\"string\" name=\"doReverse\" hint=\"I reverse the supplied string\"\u003e\n\t\t\u003ccfargument required=\"true\" type=\"string\" name=\"stringToReverse\"\u003e\n\t\t\n\t\t\u003ccfreturn reverse(arguments.stringToReverse)\u003e\n\t\u003c/cffunction\u003e\n\t\n\t\u003ccffunction access=\"public\" returntype=\"array\" name=\"reverseArrayOrder\"\u003e\n\t\t\u003ccfargument type=\"array\" name=\"arrayToReverse\" default=\"#[\"Adobe ColdFusion\", \"Lucee\", \"Railo\"]#\" hint=\"I reverse an array's order\"\u003e\n\t\t\n\t\t\u003ccfset var result = []\u003e\n\t\t\u003ccfset var i = 0\u003e\n\t\t\u003ccfloop index=\"i\" from=\"#arrayLen(arguments.arrayToReverse)#\" to=\"1\" step=\"-1\"\u003e\n\t\t\t\u003ccfset arrayAppend(result, arguments.arrayToReverse[i])\u003e\n\t\t\u003c/cfloop\u003e\n\t\t\n\t\t\u003ccfreturn result\u003e\n\t\u003c/cffunction\u003e\n\u003c/cfcomponent\u003e\n```\n\n_**Script:**_\n```coldfusion-cfc\ncomponent displayname=\"Utils\" output=\"false\" {\n\tproperty name=\"version\" type=\"string\" default=\"0.0.1\";\n\n\tpublic string function doReverse(required string stringToReverse)\n\t\thint=\"I reverse the supplied string\"\n\t{\n\t\treturn reverse(arguments.stringToReverse);\n\t}\n\t\n\tpublic array function reverseArrayOrder(array arrayToReverse = [\"Adobe ColdFusion\", \"Lucee\", \"Railo\"])\n\t\thint=\"I reverse an array's order\"\n\t{\n\t\tvar result = [];\n\t\tfor (var i = arrayLen(arguments.arrayToReverse); i \u003e= 1; i--) {\n\t\t\tresult.append(arguments.arrayToReverse[i]);\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n}\n```\n\n#### Annotations\n\n\u003e Information about a script-based component, property or function - it's attributes \u0026 arguments can be defined via the annotation syntax.\n\n_**Script:**_\n```coldfusion-cfc\n// Consider this code...\n\npublic numeric function adder(required numeric x, required numeric y)\n\thint=\"I add things\"\n{\n\treturn arguments.x + arguments.y;\n}\n\n// Now with annotations\n\n/**\n* @returnType numeric\n* @hint I add things\n*/\npublic function adder(required numeric x, required numeric y) {\n\treturn arguments.x + arguments.y;\n}\n```\n\n#### Function Expressions\n\n\u003e Consider the tag-based version of the function below. In CFScript, we can instead define a variable with an anonymous function that does the same task.\n\n_**Tags:**_\n```coldfusion\n\u003ccffunction access=\"public\" returntype=\"numeric\" name=\"adder\"\u003e\n\t\u003ccfargument required=\"true\" type=\"numeric\" name=\"x\"\u003e\n\t\u003ccfargument required=\"true\" type=\"numeric\" name=\"y\"\u003e\n\t\n\t\u003ccfreturn arguments.x + arguments.y\u003e\n\u003c/cffunction\u003e\n\n\u003ccfoutput\u003e#adder(2, 2)#\u003c/cfoutput\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\nadder = function(x, y) {\n\treturn x + y;\n};\n\nwriteOutput(adder(2, 2));\n\n// You can be more specific with type, scope, required etc.\nadder = function(required numeric x, required numeric y) {\n\treturn arguments.x + arguments.y;\n};\n\nwriteOutput(adder(2, \"a\")); // this errors\n\n\u003c/cfscript\u003e\n```\n\n### Real World Conversions By Example\n\n\u003e ##### The below examples are pieces of code found from online/offline sources. Anything with a name on it will be given credit and/or linked accordingly. If you see your code as an example and you don't want it here, LET ME KNOW! Cheers. - @cfchef\n\n#### Example 1\n\n\u003e Here's a function, written in tags, picked out from CFLib.org - [_utcOffsetToMinutes() by Mosh Teitelbaum_](http://www.cflib.org/udf/utcOffsetToMinutes)\n\n_**Tags:**_\n```coldfusion\n\u003c!---\nConverts UTC Offset to minutes.\n\n@param offset The formatted UTC offset to be converted to minutes. (Required)\n@return Returns a number.\n@author Mosh Teitelbaum (mosh.teitelbaum@evoch.com)\n@version 1, 1/8/2015\n---\u003e\n\n\u003ccffunction name=\"utcOffsetToMinutes\" returntype=\"numeric\" output=\"no\" description=\"Converts UTC Offset to minutes.\"\u003e\n\t\u003ccfargument name=\"offset\" type=\"string\" required=\"yes\" hint=\"The formatted UTC offset to be converted to minutes.\"\u003e\n\n\t\u003c!--- Initialize local variables ---\u003e\n\t\u003ccfset var h = 0\u003e\t\u003c!--- hours ---\u003e\n\t\u003ccfset var m = 0\u003e\t\u003c!--- minutes ---\u003e\n\t\u003ccfset var s = 1\u003e\t\u003c!--- sign ---\u003e\n\t\u003ccfset var str = ReReplaceNoCase(arguments.offset, \"[^-:0-9]\", \"\", \"ALL\")\u003e\t\u003c!--- offset with non-important characters removed ---\u003e\n\n\t\u003c!--- If first character is \"-\", adjust sign ---\u003e\n\t\u003ccfif Compare(Left(str, 1), \"-\") EQ 0\u003e\n\t\t\u003ccfset s = -1\u003e\n\t\t\u003ccfset str = Right(str, Len(str) - 1)\u003e\n\t\u003c/cfif\u003e\n\n\t\u003c!--- Determine number of hours and minutes ---\u003e\n\t\u003ccfif ListLen(str, \":\") EQ 2\u003e\n\t\t\u003ccfset h = ListFirst(str, \":\")\u003e\n\t\t\u003ccfset m = ListLast(str, \":\")\u003e\n\t\u003ccfelseif Len(str) EQ 2\u003e\n\t\t\u003ccfset h = str\u003e\n\t\u003ccfelseif Len(str) EQ 3\u003e\n\t\t\u003ccfset h = Left(str, 1)\u003e\n\t\t\u003ccfset m = Right(str, 2)\u003e\n\t\u003ccfelseif Len(str) EQ 4\u003e\n\t\t\u003ccfset h = Left(str, 2)\u003e\n\t\t\u003ccfset m = Right(str, 2)\u003e\n\t\u003c/cfif\u003e\n\n\t\u003c!--- Return number of minutes ---\u003e\n\t\u003ccfreturn s * ((h * 60) + m)\u003e\n\u003c/cffunction\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n/**\n* @hint Converts UTC Offset to minutes.\n* @param offset The formatted UTC offset to be converted to minutes. (Required)\n* @return Returns a number.\n* @author Mosh Teitelbaum (mosh.teitelbaum@evoch.com)\n* @version 1, 1/8/2015\n*/\npublic numeric function utcOffsetToMinutes(required string offset) {\n\t// Initialize local variables\n\tvar h = 0; // hours\n\tvar m = 0; // minutes\n\tvar s = 1; // sign\n\tvar str = reReplaceNoCase(arguments.offset, \"[^-:0-9]\", \"\", \"ALL\"); // offset with non-important characters removed\n\n\t// If first character is \"-\", adjust sign\n\tif (compare(left(str, 1), \"-\") == 0) {\n\t\ts = -1;\n\t\tstr = right(str, len(str) - 1);\n\t}\n\n\t// Determine number of hours and minutes\n\tif (listLen(str, \":\") == 2) {\n\t\th = listFirst(str, \":\");\n\t\tm = listLast(str, \":\");\n\t} else if (len(str) == 2) {\n\t\th = str;\n\t} else if (len(str) == 3) {\n\t\th = left(str, 1);\n\t\tm = right(str, 2);\n\t} else if (len(str) == 4) {\n\t\th = left(str, 2);\n\t\tm = right(str, 2);\n\t}\n\n\t// Return number of minutes\n\treturn s * ((h * 60) + m);\n}\n\n\u003c/cfscript\u003e\n```\n\n#### Example 2\n\n\u003e Here's another one from CFLib.org - [_addRemoveDebuggingIPAddress() by Qasim Rasheed_](http://www.cflib.org/udf/addRemoveDebuggingIPAddress)\n\n_**Tags:**_\n```coldfusion\n\u003c!---\n This function will either add or remove an IP address to the list of debugging ip addresses if you do not have an administrator access.\n \n @param ipAddress \t IP Address (Required)\n @param action \t Add or Remove. Defaults to Add. (Optional)\n @return Returns a list of IP addresses. \n @author Qasim Rasheed (qasim_1976@yahoo.com) \n @version 1, February 17, 2004 \n---\u003e\n\u003ccffunction name=\"addRemoveDebuggingIPAddress\" output=\"false\" returnType=\"string\"\u003e\n\t\u003ccfargument name=\"IPaddress\" type=\"string\" required=\"Yes\" /\u003e\n\t\u003ccfargument name=\"action\" type=\"string\" default=\"Add\" /\u003e\n\t\u003ccfscript\u003e\n\t\tvar factory = CreateObject(\"Java\",\"coldfusion.server.ServiceFactory\");\n\t\tvar debuggingService = \"\";\n\t\u003c/cfscript\u003e\n\t\u003ccflock name=\"factory_debuggingservice\" type=\"exclusive\" timeout=\"5\"\u003e\n\t\t\u003ccfset debuggingService = factory.getDebuggingService()\u003e\n\t\t\u003ccfswitch expression=\"#arguments.action#\"\u003e\n\t\t\t\u003ccfcase value=\"Add\"\u003e\n\t\t\t\t\u003ccfif not listcontainsnocase(debuggingService.iplist.ipList,arguments.IPaddress)\u003e\n\t\t\t\t\t\u003ccfset debuggingService.iplist.ipList = ListAppend(debuggingService.iplist.ipList,arguments.IPaddress)\u003e\n\t\t\t\t\u003c/cfif\u003e\n\t\t\t\u003c/cfcase\u003e\n\t\t\t\u003ccfcase value=\"Remove\"\u003e\n\t\t\t\t\u003ccfif listcontainsnocase(debuggingService.iplist.ipList,arguments.IPaddress)\u003e\n\t\t\t\t\t\u003ccfset debuggingService.iplist.ipList = ListDeleteAt(debuggingService.iplist.ipList,ListFindNoCase(debuggingService.iplist.ipList,arguments.IPaddress))\u003e\n\t\t\t\t\u003c/cfif\u003e\n\t\t\t\u003c/cfcase\u003e\n\t\t\u003c/cfswitch\u003e\n\t\t\u003ccfreturn debuggingService.iplist.ipList /\u003e\n\t\u003c/cflock\u003e\n\u003c/cffunction\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n/**\n* @hint This function will either add or remove an IP address to the list of debugging ip addresses if you do not have an administrator access.\n* @param ipAddress IP Address (Required)\n* @param action Add or Remove. Defaults to Add. (Optional)\n* @return Returns a list of IP addresses. \n* @author Qasim Rasheed (qasim_1976@yahoo.com) \n* @version 1, February 17, 2004 \n*/\npublic string function addRemoveDebuggingIPAddress(required string IPaddress, string action = \"Add\")\n\toutput=\"false\"\n{\n\tvar factory = createObject(\"java\",\"coldfusion.server.ServiceFactory\");\n\tvar debuggingService = \"\";\n\tlock name=\"factory_debuggingservice\" type=\"exclusive\" timeout=\"5\" {\n\t\tdebuggingService = factory.getDebuggingService();\n\t\tswitch(arguments.action) {\n\t\t\tcase \"Add\":\n\t\t\t\tif (!listContainsNoCase(debuggingService.iplist.ipList,arguments.IPaddress)) {\n\t\t\t\t\tdebuggingService.iplist.ipList = listAppend(debuggingService.iplist.ipList, arguments.IPaddress);\n\t\t\t\t}\n\t\t\tbreak;\n\t\t\tcase \"Remove\":\n\t\t\t\tif (listContainsNoCase(debuggingService.iplist.ipList, arguments.IPaddress)) {\n\t\t\t\t\tdebuggingService.iplist.ipList = listDeleteAt(debuggingService.iplist.ipList, listFindNoCase(debuggingService.iplist.ipList, arguments.IPaddress));\n\t\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\treturn debuggingService.iplist.ipList;\n\t}\n}\n\n\u003c/cfscript\u003e\n```\n\n#### Example 3\n\n\u003e Yet another example from CFLib.org - [_collectFiles() by Steven Ross_](http://www.cflib.org/udf/collectFiles)\n\n_**Tags:**_\n```coldfusion\n\u003c!---\n Scans a directory (or path) for files of a specified extension and then copies them to the path you specify.\n v2 by Raymond Camden. I just cleaned up the var statements.\n \n @param extensions \t List of extensions to copy. (Required)\n @param destinationPath \t Destination directory. (Required)\n @param sourcePath \t Source directory. (Required)\n @return Returns nothing. \n @author Steven Ross (steven.ross@zerium.com) \n @version 2, April 7, 2006 \n---\u003e\n\u003ccffunction name=\"collectFiles\" access=\"public\" hint=\"recurses through a directory and collects the file types you want then outputs to another directory\" returnType=\"void\"\u003e\n\t\u003ccfargument name=\"extensions\" required=\"true\" type=\"string\" hint=\"The extensions you want to gather up csv (list) format ex:(asp,cfm,jsp) \"\u003e\n\t\u003ccfargument name=\"destinationPath\" required=\"true\" type=\"string\" hint=\"absolute path to storage directory\"\u003e\n\t\u003ccfargument name=\"sourcePath\" required=\"true\" type=\"string\" hint=\"absolute path to source directory\"\u003e\n\t\u003ccfset var root = arguments.sourcePath/\u003e\n\t\u003ccfset var i = \"\"\u003e\n\t\u003ccfset var absPath = \"\"\u003e\n\t\u003ccfset var relativePath = \"\"\u003e\n\t\u003ccfset var writeTo = \"\"\u003e\n\t\u003ccfset var pathAndFile = \"\"\u003e\n\t\n\t\u003ccfif not directoryExists(arguments.sourcePath)\u003e\n\t\t\u003ccfthrow message=\"Source Directory (#arguments.sourcePath#) not found\" detail=\"You didn't pass in a valid source directory, check the path and try again.\"\u003e\n\t\u003c/cfif\u003e\n\t\n\t\u003ccfloop list=\"#arguments.extensions#\" index=\"i\"\u003e\n\t\t\u003ccfdirectory name=\"getFiles\" directory=\"#root#\" recurse=\"true\" filter=\"*.#i#\"\u003e\n\t\t\u003ccfloop query=\"getFiles\"\u003e\n\t\t\t\u003ccfset absPath = getFiles.directory \u0026 \"/\" /\u003e\n\t\t\t\u003ccfset relativePath = Replace(absPath, root, \"\", \"all\") /\u003e\n\t\t\t\u003ccfset writeTo = ARGUMENTS.destinationPath \u0026 \"/\" \u0026 relativePath\u003e\n\t\t\t\u003ccfset pathAndFile = getFiles.directory \u0026 \"/\" \u0026 getFiles.name /\u003e\n\t\t\t\u003ccfif not directoryExists(writeTo)\u003e\n\t\t\t\t\u003ccfdirectory action=\"create\" directory=\"#writeTo#\"\u003e\n\t\t\t\t\u003ccffile action=\"copy\" source=\"#pathAndFile#\" destination=\"#writeTo#\"\u003e\n\t\t\t\u003ccfelse\u003e\n\t\t\t\t\u003ccffile action=\"copy\" source=\"#pathAndFile#\" destination=\"#writeTo#\"\u003e\n\t\t\t\u003c/cfif\u003e\n\t\t\u003c/cfloop\u003e\n\t\u003c/cfloop\u003e\n\u003c/cffunction\u003e\n```\n\n_**Script:**_\n```coldfusion\n\u003ccfscript\u003e\n\n/**\n* @hint Scans a directory (or path) for files of a specified extension and then copies them to the path you specify.\n* @param extensions List of extensions to copy. (Required)\n* @param destinationPath Destination directory. (Required)\n* @param sourcePath Source directory. (Required)\n* @return Returns nothing.\n* @author Steven Ross (steven.ross@zerium.com) - v2 by Raymond Camden. I just cleaned up the var statements.\n* @version 2, April 7, 2006\n*/\npublic void function collectFiles(required string extensions, required string destinationPath, required string sourcePath) {\n\tvar root = arguments.sourcePath;\n\tif (!directoryExists(arguments.sourcePath)) {\n\t\tthrow(\n\t\t\tmessage = \"Source Directory (#arguments.sourcePath#) not found\",\n\t\t\tdetail = \"You didn't pass in a valid source directory, check the path and try again.\"\n\t\t);\n\t}\n\tfor (var ext in listToArray(arguments.extensions)) {\n\t\tvar list = directoryList(path = root, recurse = true, listinfo = \"query\", filter = \"*.#ext#\");\n\t\tfor (var dir in list) {\n\t\t\tvar absPath = dir.directory \u0026 \"/\";\n\t\t\tvar relativePath = replace(absPath, root, \"\", \"all\");\n\t\t\tvar writeTo = arguments.destinationPath \u0026 \"/\" \u0026 relativePath;\n\t\t\tvar pathAndFile = dir.directory \u0026 \"/\" \u0026 dir.name;\n\t\t\tif (!directoryExists(writeTo)) {\n\t\t\t\tdirectoryCreate(writeTo);\n\t\t\t\tfileCopy(pathAndFile, writeTo);\n\t\t\t} else {\n\t\t\t\tfileCopy(pathAndFile, writeTo);\n\t\t\t}\n\t\t}\n\t}\n}\n\n\u003c/cfscript\u003e\n```\n\n### Tags Have Their Place\n\n#### Keeping Tags in the View\n\n\u003e The modern CFML world has evolved with various flavors and mixes of Model View Controller (MVC) \u0026 Object Oriented Programming (OOP) practices. While procedural coding might have a place, larger applications often call for a more organized, structured collection of functions and how and where they display their results. As opposed to being \u003cem\u003eall\u003c/em\u003e in one file, database calls should reside in their own file (Model), structuring/manipulation of that data can be built in a seperate file based on user supplied variables (Controller) and then that structured data is formatted with HTML for display (View).\n\n\u003e From a general standpoint, the view layer should be the home for basic tag functions to help iterate and organize received result data; to be married with your HTML and displayed to the user. Simple tags such as `\u003ccfset\u003e`, `\u003ccfparam\u003e`, `\u003ccfoutput\u003e`, `\u003ccfif\u003e` \u0026 `\u003ccfloop\u003e`. With the involvement of HTML in the view, tags make sense as they work with the flow of the layout; leaving your Model and Controllers to be uncluttered and have a clean flow of their own in CFScript. It might be a matter of opinion but you will eventually grow to find this separation quite refreshing visually and mentally when scanning through large blocks of logic vs display code.\n\nConsider this general mock breakdown of code presenting blog posts to the user. This would normally be handled more effectively \u0026 efficiently in a MVC framework like [FW/1](http://framework-one.github.io/) or [Coldbox](http://www.coldbox.org/).\n\n_**Model: BlogService.cfc**_\n\n```coldfusion-cfc\n/**\n* @hint I contain blog related utilities\n*/\ncomponent displayname=\"Blog Service\"\n\toutput=\"false\"\n{\n\t/**\n\t* @hint I intiate the service object by setting the datasource\n\t*/\n\tpublic BlogService function init(required string dsn) {\n\t\tvariables.dsn = arguments.dsn;\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t* @hint I return a query of blog posts\n\t*/\n\tpublic query function getPosts() {\n\t\tvar qry = new Query();\n\t\tqry.setDatasource(variables.dsn);\n\t\tqry.setSQL(\"\n\t\t\tSELECT postId, postTitle, postBody, author, publishDate\n\t\t\tFROM posts\n\t\t\tORDER BY postId DESC\n\t\t\");\n\t\t\n\t\treturn qry.execute().getResult();\n\t}\n}\n```\n\n_**Controller: BlogController.cfc**_\n\n```coldfusion-cfc\n/**\n* @hint I receive user request and translate them into response\n*/\ncomponent displayname=\"Blog Controller\"\n\toutput=\"false\"\n{\n\t/**\n\t* @hint I initiate the BlogController and call in all required objects\n\t*/\n\tpublic BlogController funtion init() {\n\t\tvar DataService = createObject(\"component\", \"model.services.DataService\").init();\n\t\tvariables.BlogService = createObject(\"component\", \"model.services.BlogService\").init(DataService.getDSN());\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t* @hint I return a formatted collection of blog posts for display\n\t*/\n\tpublic struct function posts() {\n\t\t// Define out request context struct for holding data to pass on to the view\n\t\tvar rc = {};\n\t\tvar postQry = variables.BlogService.getPosts();\n\t\t// Let's make a friendlier collection as a array of structs of the data\n\t\trc.posts = [];\n\t\tif (postQuery.recordCount) {\n\t\t\tfor (var post in postQry) {\n\t\t\t\tarrayAppend(rc.posts, {\n\t\t\t\t\ttitle: post.postTitle,\n\t\t\t\t\tbody: post.postBody,\n\t\t\t\t\tauthor: post.author,\n\t\t\t\t\tpublished: post.publishDate\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn rc;\n\t}\n}\n```\n\n_**View: posts.cfm**_\n\n```coldfusion\n\u003ccfparam name=\"rc.posts\" default=\"#[]#\"\u003e\n\n\u003ccfset BlogController = createObject(\"component\", \"blog.controllers.BlogController\").init()\u003e\n\u003ccfset rc.posts = BlogController.posts()\u003e\n\n\u003ch1\u003eWelcome to my Blog!\u003c/h1\u003e\n\u003ccfif arrayLen(rc.posts)\u003e\n\t\u003cdiv class=\"post-content\"\u003e\n\t\u003ccfoutput\u003e\n\t\u003ccfloop index=\"post\" array=\"#rc.posts#\"\u003e\n\t\t\u003ch2\u003e#post.title#\u003c/h2\u003e\n\t\t\u003cdiv class=\"post-meta\"\u003ePublished on: #post.published# By: #post.author#\u003c/div\u003e\n\t\t\u003cdiv class=\"post-body\"\u003e#post.body#\u003c/div\u003e\n\t\u003c/cfloop\u003e\n\t\u003c/cfoutput\u003e\n\t\u003c/div\u003e\n\u003ccfelse\u003e\n\t\u003ch3\u003eNo posts to display!\u003c/h3\u003e\n\u003c/cfif\u003e\n```\n\n#### Building Tag Code on the Script Side\n\n\u003e While we generally want to keep our presentation layer separate from our business logic, as briefly portrayed in [Keeping Tags in the View](https://github.com/cfchef/cfml-tag-to-script-conversions/blob/master/README.md#keeping-tags-in-the-view), there are some scenarios where we need to do string-building in a function, or similar, to later pass on for an alternate method of viewing in HTML, XML, email etc.\n\nConsider these examples. . .\n\n_**Email - Tags**_\n\n```coldfusion\n\u003c!--- Dummy blog post ---\u003e\n\u003ccfset post = {\n\ttitle: \"My New Blog Post!\",\n\tslug: \"my-new-blog-post\",\n\tbody: \"Some body content for the post.\",\n\tpublishDate: \"{ts '2015-07-06 18:17:01'}\"\n}\u003e\n\n\u003c!--- Build our email ---\u003e\n\u003ccfsavecontent variable=\"mailBody\"\u003e\n\t\u003ccfoutput\u003e\n\t\t\u003ch4\u003eA New Article Has Been Posted @ myblog.com!\u003c/h4\u003e\n\t\t\u003ch6\u003e#post.title#\u003c/h6\u003e\n\t\t\u003cp\u003e\u003cb\u003ePosted on:\u003c/b\u003e #dateFormat(post.publishDate, \"YYYY/MM/DD\")#\u003c/p\u003e\n\t\t\u003cp\u003e\n\t\t\t\u003ccfif len(post.body) GT 500\u003e\n\t\t\t\t#left(post.body, 500)#. . .\n\t\t\t\u003ccfelse\u003e\n\t\t\t\t#post.body#\n\t\t\t\u003c/cfif\u003e\n\t\t\u003c/p\u003e\n\t\t\u003ca href=\"http://myblog.com/blog/#post.slug#\"\u003e\u003cb\u003eRead more...\u003c/b\u003e\u003c/a\u003e\n\t\u003c/cfoutput\u003e\n\u003c/cfsavecontent\u003e\n\n\u003c!--- Send email to subscribers ---\u003e\n\u003ccfloop item=\"subscriber\" collection=\"#SubscriberService.getSubscribers()#\"\u003e\n\t\u003ccfmail\n\t\ttype=\"html\"\n\t\tto=\"#subscriber.getEmail()#\"\n\t\tfrom=\"no-reply@myblog.com\"\n\t\tsubject=\"New Blog Post from MyBlog.com\"\n\t\tbody=\"#mailBody#\"\n\t\u003e\n\u003c/cfloop\u003e\n```\n\n_**Email - Script**_\n\n```coldfusion\n\u003ccfscript\u003e\n\n// Dummy blog post\npost = {\n\ttitle: \"My New Blog Post!\",\n\tslug: \"my-new-blog-post\",\n\tbody: \"Some body content for the post.\",\n\tpublishDate: \"{ts '2015-07-06 18:17:01'}\"\n};\n\n// Build our email\nsavecontent variable=\"mailBody\" {\n\twriteOutput('\n\t\t\u003ch4\u003eA New Article Has Been Posted @ myblog.com!\u003c/h4\u003e\n\t\t\u003ch6\u003e#post.title#\u003c/h6\u003e\n\t\t\u003cp\u003e\u003cb\u003ePosted on:\u003c/b\u003e #dateFormat(post.publishDate, \"YYYY/MM/DD\")#\u003c/p\u003e\n\t\t\u003cp\u003e\n\t\t\tif (len(post.body) \u003e 500) {\n\t\t\t\t#left(post.body, 500)#. . .\n\t\t\t} else {\n\t\t\t\t#post.body#\n\t\t\t}\n\t\t\u003c/p\u003e\n\t\t\u003ca href=\"http://myblog.com/blog/#post.slug#\"\u003e\u003cb\u003eRead more...\u003c/b\u003e\u003c/a\u003e\n\t');\n};\n\n// Send email to subscribers\nfor (subscriber in SubscriberService.getSubscribers()) {\n\tmailService = new mail(\n\t\ttype = \"html\",\n\t\tto = subscriber.getEmail(),\n\t\tfrom = \"no-reply@myblog.com\",\n\t\tsubject = \"New Blog Post from MyBlog.com!\",\n\t\tbody = encodeForHTML(mailBody)\n\t);\n\tmailService.send();\n}\n\n\u003c/cfscript\u003e\n```\n\n\n_**XML Sitemap - Tags**_\n\n```coldfusion\n\u003c!--- Dummy links ---\u003e\n\u003ccfset links = [\n\t\"http://myblog.com\",\n\t\"http://myblog.com/about\",\n\t\"http://myblog.com/blog\",\n\t\"http://myblog.com/blog/my-blog-post\"\n]\u003e\n\n\u003ccftry\u003e\n\t\u003c!--- Build XML ---\u003e\n\t\u003ccfsavecontent variable=\"xmlData\"\u003e\n\t\u003ccfoutput\u003e\n\t\t\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\t\t\u003curlset\n\t\t\txmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n\t\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\t\t\txsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n\t\t\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"\u003e\n\t\t\u003ccfloop index=\"link\" array=\"#links#\"\u003e\n\t\t\t\u003curl\u003e\n\t\t\t  \u003cloc\u003e#link#\u003c/loc\u003e\n\t\t\t  \u003cchangefreq\u003eweekly\u003c/changefreq\u003e\n\t\t\t  \u003cpriority\u003e0.8\u003c/priority\u003e\n\t\t\t\u003c/url\u003e\n\t\t\u003c/cfloop\u003e\n\t\t\u003c/urlset\u003e\n\t\u003c/cfoutput\u003e\n\t\u003c/cfsavecontent\u003e\n\t\n\t\u003c!--- Write to file ---\u003e\n\t\u003ccffile action=\"write\" file=\"#expandPath(\"./Sitemap.xml\")#\" output=\"#xmlData#\"\u003e\n\n\t\u003ccfcatch type=\"any\"\u003e\n\t\t\u003ccfoutput\u003e#cfcatch.message#\u003c/cfoutput\u003e\n\t\u003c/cfcatch\u003e\n\u003c/cftry\u003e\n```\n\n_**XML Sitemap - Script**_\n\n```coldfusion\n\u003ccfscript\u003e\n\n// Dummy links\nlinks = [\n\t\"http://myblog.com\",\n\t\"http://myblog.com/about\",\n\t\"http://myblog.com/blog\",\n\t\"http://myblog.com/blog/my-blog-post\"\n];\n\ntry {\n\t// Build XML\n\tsavecontent variable=\"xmlData\" {\n\t\twriteOutput('\n\t\t\t\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\t\t\t\u003curlset\n\t\t\t\txmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n\t\t\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\t\t\t\txsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n\t\t\t\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"\u003e\n\t\t');\n\t\tfor (link in links) {\n\t\t\twriteOutput('\n\t\t\t\t\u003curl\u003e\n\t\t\t\t  \u003cloc\u003e#link#\u003c/loc\u003e\n\t\t\t\t  \u003cchangefreq\u003eweekly\u003c/changefreq\u003e\n\t\t\t\t  \u003cpriority\u003e0.8\u003c/priority\u003e\n\t\t\t\t\u003c/url\u003e\n\t\t\t');\n\t\t}\n\t\twriteOutput('\n\t\t\t\u003c/urlset\u003e\n\t\t');\n\t}\n\t// Write to file\n\tfileWrite(expandPath(\"./Sitemap.xml\"), xmlData);\n}\ncatch(any e) {\n\twriteOutput(e.message);\n}\n\n\u003c/cfscript\u003e\n```\n\n## LICENSE\n\u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\"\u003e\u003cimg alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by/4.0/88x31.png\" /\u003e\u003c/a\u003e\u003cbr /\u003e\u003cspan xmlns:dct=\"http://purl.org/dc/terms/\" property=\"dct:title\"\u003eCFML Tag to Script Conversions\u003c/span\u003e by \u003ca xmlns:cc=\"http://creativecommons.org/ns#\" href=\"http://tonyjunkes.com/blog/leave-your-tags-at-the-door-some-cfml-tag-to-script-documentation\" property=\"cc:attributionName\" rel=\"cc:attributionURL\"\u003eTony Junkes\u003c/a\u003e is licensed under a \u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\"\u003eCreative Commons Attribution 4.0 International License\u003c/a\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyjunkes%2Fcfml-tags-to-cfscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonyjunkes%2Fcfml-tags-to-cfscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyjunkes%2Fcfml-tags-to-cfscript/lists"}