How to store a ColdFusion # variable in MySQL and display the value of the variable (not the name of the variable) in the database?

advertisements

I'm running Coldfusion8/MySQL 5.0.88.

I have two tables in my database:

modules
textblocks

My site is running multiple languages, so I'm doing this at the beginning of every page to load textblocks from the database depending on user-selected language.

<cfquery datasource="#Session.datasource#" name="texte">
   SELECT *
   FROM textblocks
   WHERE lang = <cfqueryparam value = "#Session.lang#" cfsqltype="cf_sql_varchar" maxlength="2">
</cfquery>
<cfoutput query="texte">
    <cfset "#trim(label)#" = "#trim(content)#">
</cfoutput>

If I need a textblock I can then simply use the label like so:

<cfoutput>#tx_hello_world#</cfoutput>

My problem is with the 2nd table which contains a list of modules.

Each module has it's own description (headers, subheaders, info, bullets 1-5). I have to loop through all modules (25) so I just stored the labels in the database, hoping to do a single loop and output the labels from the database. Unfortunately outputting label123 returns

 #label123#

vs me hoping for

 "text from table textblocks stored at label123"

Question:
Is it possible to store "dynamic variables" in MySQL and upon outputting these, retrieve the underlying value for them? If not, what is a better approach of outputting 25 modules in a single loop without saying "if this is module A, take text tx_module_a_title, else if ..."

Thanks!

EDIT:
So I'm hoping to avoid this having to run on every loop:

<cfif mods.module_name EQ "agents">
    <cfset variables.module_header = tx_module_b2b_agents_title>
    <cfset variables.module_subheader = tx_module_b2b_agents>
    <cfset variables.module_info = tx_module_b2b_agents_info>
    <cfset variables.module_bull_1 = tx_module_b2b_agn_accounts>
    <cfset variables.module_bull_2 = tx_module_b2b_agn_price_clients>
    <cfset variables.module_bull_3 = tx_module_b2b_agn_client_mgt>
    <cfset variables.module_bull_4 = tx_module_b2b_agn_create_retailer>
    <cfset variables.module_bull_5 = tx_module_b2b_exp_grace>
    <cfset variables.module_usage_tx = tx_vertreter/tx_gen_month>
<cfelseif mods.module_name EQ "preorder">
    <cfset variables.module_header = tx_module_b2b_preorder_title>
    <cfset variables.module_subheader = tx_module_b2b_preorder>
    <cfset variables.module_info = tx_module_b2b_preord_info>
    <cfset variables.module_bull_1 = tx_module_b2b_pre_split_type>
    <cfset variables.module_bull_2 = tx_module_b2b_pre_qty_y_n>
    <cfset variables.module_bull_3 = tx_module_b2b_pre_deliverydate>
    <cfset variables.module_bull_4 = tx_module_b2b_exp_grace>
    <cfset variables.module_bull_5 = "">
    <cfset variables.module_usage_tx = tx_gen_month >
<cfelseif mods.module_name EQ "export">
    <cfset variables.module_header = tx_module_b2b_export_title>
    <cfset variables.module_subheader = tx_module_b2b_export>
    <cfset variables.module_info = tx_module_b2b_export_info>
    <cfset variables.module_bull_1 = tx_module_b2b_exp_pricelists>
    <cfset variables.module_bull_2 = tx_module_b2b_exp_currencies>
    <cfset variables.module_bull_3 = tx_module_b2b_exp_customerlist>
    <cfset variables.module_bull_4 = tx_module_b2b_exp_regional_assortme>
    <cfset variables.module_bull_5 = tx_module_b2b_exp_grace>
    <cfset variables.module_usage_tx = tx_gen_month>
... 22 else-ifs to go
</cfif>

If I could store the textblock behind the tx_ values in the database module record I could retrieve them from there.


When you output the content from the db you can use de() and evalaute() on the content to process the vars. You will likely need to use a nested combination. I forget the exact syntax. De(evaluate('#var#')) or something like that.

However this will prove problematic if you have any other # in the content that is not a var. I would suggest using lexicons instead. See this article Content Management : Processing Dynamic Content