Loading ...
Sorry, an error occurred while loading the content.

Re: [Cheetahtemplate-discuss] Using a variable inside another variable name

Expand Messages
  • Oliver Nicholas
    $getVar( sso_host_%s % $myLanguage) ... -- oliver phillip nicholas *computer whisperer* http://bigo.yelp.com/ $getVar( sso_host_%s % $myLanguage) On Mon, Sep
    Message 1 of 2 , Sep 19, 2011
    • 0 Attachment
      $getVar("sso_host_%s" % $myLanguage)

      On Mon, Sep 19, 2011 at 10:04 AM, Rémi ALVADO <remi.alvado@...> wrote:

      I'm new with Cheetah and I'm trying to use it to build a deployment tool and replace my old configuration files with brand new cheetah templates. 
      I'm working for a company which edit websites all over the world so lots of our configuration keys are overriden by country.
      With Cheetah, I'm storing my configuration into a YAML data storage files and I use a Python script combined with some Bash scripts to find, fill and replace all *.cheetah files. 
      Please find below an example of my test configuration file, my YAML data storage and the expected result file

      --------------- CONF FILE -------------------
      #for myLanguage in $cultures
              host:   $eval("sso_host_" + myLanguage)
              port:   $eval("sso_port_" + myLanguage)
      #end for

      --------------- YAML DATA STORAGE -------------------
      # Global 
        - de
        - en
        - fr

      # DE
      sso_host_de:         sso-de.example.com
      sso_port_de:         8081

      # EN
      sso_host_en:         sso-en.example.com
      sso_port_en:         8082

      # FR
      sso_host_fr:         sso-fr.example.com
      sso_port_fr:         8083

      --------------- YAML DATA STORAGE -------------------
              host:   sso-de.example.com
              port:   8081
              host:   sso-en.example.com
              port:   8082
              host:   sso-fr.example.com
              port:   8083


      I know using "eval" is not a good idea (eval = evil :) ) but I've tried several other  solutions ("$sso_public_host_$myLanguage", "$(sso_public_host_$myLanguage)", ...) and none of them work.
      I've also tried to change my data storage file to have something like :
         sso_host_public: ...
      but I've got the exact same issue with $self[$myLanguage]['sso_host_public'] and I don't like this representation since it's less natural than a list of <key,value> tuples.

      Do you have any idea how I can use a variable inside another variable name ? It seems to be a bit odd but it would be very convenient in a production environnement to have a very simple data storage file with only <key,value> tuples : easy to read and easy to share with a simple copy/paste into release note on a mail, a twiki, ...

      Thanks and congratulations this templating engine : despite this little issue, it's really great and I might consider using it on another projects, more web oriented :)


      BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
      Learn about the latest advances in developing for the
      BlackBerry&reg; mobile platform with sessions, labs & more.
      See new tools and technologies. Register for BlackBerry&reg; DevCon today!
      Cheetahtemplate-discuss mailing list

      oliver phillip nicholas
      computer whisperer

    Your message has been successfully submitted and would be delivered to recipients shortly.