structToTable – Generate HTML/Text Output for Display/Email

When working on new logic and I want to dump a variable, I often use an internal CF_DumpLite CFC/CFTag that we developed that minimizes HTML output, honors original form & query column order & case, redacts CC values and is nonce aware. If I ne…


This content originally appeared on DEV Community and was authored by James Moberg

When working on new logic and I want to dump a variable, I often use an internal CF_DumpLite CFC/CFTag that we developed that minimizes HTML output, honors original form & query column order & case, redacts CC values and is nonce aware. If I need to view the data types, I switch it up to use the cf_dump CFTag by Alexander Kwaschny.

We occasionally need to output data from an unordered struct in an email or to the webpage and it's not optimal to use either of these developer-centric dump tools for the general public. Even though we've been manually displaying tables for years, we've tended to repeat ourselves. I wrote this UDF in an effort to avoid having to do that.

structToTable is a ColdFusion UDF that will accept a struct with key-value pairs to generate legacy-valid, email-friendly html table and text-only key-value output.

We're now using this UDF when generating email messages so that we have both HTML and TEXT versions of the data. Enjoy!

Example Usage

result = structToTable(data=CGI,
  keysToRemove="SERVER_PORT", sortOrder="https,auth_user");

writeoutput(result.html);

writeoutput("\<pre\>" & result.text & "\</pre\>");

Source Code

https://gist.github.com/JamoCA/bc5c58e829e191947f2e34289fd98a5a


This content originally appeared on DEV Community and was authored by James Moberg


Print Share Comment Cite Upload Translate Updates
APA

James Moberg | Sciencx (2024-10-28T23:35:18+00:00) structToTable – Generate HTML/Text Output for Display/Email. Retrieved from https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/

MLA
" » structToTable – Generate HTML/Text Output for Display/Email." James Moberg | Sciencx - Monday October 28, 2024, https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/
HARVARD
James Moberg | Sciencx Monday October 28, 2024 » structToTable – Generate HTML/Text Output for Display/Email., viewed ,<https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/>
VANCOUVER
James Moberg | Sciencx - » structToTable – Generate HTML/Text Output for Display/Email. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/
CHICAGO
" » structToTable – Generate HTML/Text Output for Display/Email." James Moberg | Sciencx - Accessed . https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/
IEEE
" » structToTable – Generate HTML/Text Output for Display/Email." James Moberg | Sciencx [Online]. Available: https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/. [Accessed: ]
rf:citation
» structToTable – Generate HTML/Text Output for Display/Email | James Moberg | Sciencx | https://www.scien.cx/2024/10/28/structtotable-generate-html-text-output-for-display-email/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.