1 Reply Latest reply on Sep 20, 2006 6:47 AM by Swift

    How to Create a Variable within a Variable?

    Oliver_Cookson Level 1
      Hi,

      I want to create a non-generic .cfm file which is created with <CFFILE>. The output of the file is below in the quotes. I am using <CFSAVECONTENT> to save this but the problem is CFML actually parses the variables rather than using it to store in a variable... I don't want the variables parsed until I display the variable created by <CFSAVECONTENT> (when we write the .cfm file.

      I hope that makes sense? Thanks! :)

      quote:


      <!--- build section phrases --->
      <CFSET sectionPhrase = "#FORM.title#, #FORM.subTitle#">
      <CFSET metaKeywords = "#FORM.title#, #FORM.subTitle#">
      <CFSET metaDesc = "#FORM.title#, #FORM.subTitle#, UK suppliers of cheap #FORM.title#.">


      <!--- includes --->
      <CFINCLUDE TEMPLATE="#REQUEST.baseWebURL#inc/header.cfm">
      <CFINCLUDE TEMPLATE="#REQUEST.baseWebURL#inc/leftMenu.cfm">
      <CFINCLUDE TEMPLATE="#REQUEST.baseWebURL#inc/ingredientShow.cfm">

        • 1. Re: How to Create a Variable within a Variable?
          Swift
          Oliver,

          If I understand you correctly, what you want is dynamic variable evaluation, and ColdFusion does it better than any language I've seen!

          Instead of:
          <!--- build section phrases --->
          <CFSET sectionPhrase = "#FORM.title#, #FORM.subTitle#">
          <CFSET metaKeywords = "#FORM.title#, #FORM.subTitle#">
          <CFSET metaDesc = "#FORM.title#, #FORM.subTitle#, UK suppliers of cheap #FORM.title#.">


          Try:
          <!--- build section phrases --->
          <CFSET sectionPhrase = "##FORM.title##, ##FORM.subTitle##">
          <CFSET metaKeywords = "##FORM.title##, ##FORM.subTitle##">
          <CFSET metaDesc = "##FORM.title##, ##FORM.subTitle##, UK suppliers of cheap ##FORM.title##.">


          And then, to evaluate them use:

          <CFOutput>
          #Evaluate(DE(SectionPhrase))#
          #Evaluate(DE(MetaKeywords))#
          #Evaluate(DE(MetaDesc))#
          </CFOutput>

          I'm not sure if this is exactly what you want your code to do, but hopefully you can extract the principle of dynamic variables out of it, and use it to get it to do what you want.

          HTH
          Swift