Skip to content

Instantly share code, notes, and snippets.

@steinbring
Created September 2, 2013 20:03
Show Gist options
  • Save steinbring/6416774 to your computer and use it in GitHub Desktop.
Save steinbring/6416774 to your computer and use it in GitHub Desktop.
This is an experiment in the dynamic population of a variable scope, based upon the content within a table. It could be really useful for the localization of content.
<cfsilent>
<cfif isDefined("url.language")>
<cfquery name="VocabQuery" datasource="erp">
select vcName as name,
vcValue as value,
vcLanguage as language
from tblVocab
where vcLanguage = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.language#">
</cfquery>
<cfset variables.vocabulary = StructNew()>
<cfloop from="1" to="#VocabQuery.recordcount#" index="i">
<cfset "variables.vocabulary.#VocabQuery.name[i]#" = trim(VocabQuery.value[i])>
</cfloop>
</cfif>
</cfsilent>
<form method="get">
<select name="language">
<option value="en">English</option>
<option value="sp">Spanish</option>
<option value="la">Latin</option>
</select>
<input type="submit" name="submit" value="Load">
</form>
<cfif isDefined("variables.vocabulary")>
<cfdump var="#variables.vocabulary#">
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment