Re: [SMARTY] Replacing smarty variable from an associative array's values

From: Date: Sat, 08 Feb 2003 12:31:38 +0000
Subject: Re: [SMARTY] Replacing smarty variable from an associative array's values
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7594@lists.php.net to get a copy of this message
Thanks Ruslan and yes nested {} tags are illegal :) {$ISO3166_CODE_TO_NATURAL.$Country} seems to work, but only when $Country is simple variable. When I tried using an object variable, $product->Country, like this {$ISO3166_CODE_TO_NATURAL.$product->Country} it did not work until I used an temporary simple variable: {assign var="$product->Country" value"$product->Country"} and then again {$ISO3166_CODE_TO_NATURAL.$Country} now it works, but using this temporary variable only, wonder what might be the reason for this? gawan "Savajr" <savajr@avalon.te.ua> wrote in message news:005701c2cf68$640edfc0$299ba8c0@wizard... > > Try constructions like {$assoc_array.$var} or {assoc_array[$var]} > > {$ISO3166_CODE_TO_NATURAL.$Country} > Or > {$ISO3166_CODE_TO_NATURAL[$Country]} > > --------------- > Ruslan Savchyshyn > http://www.MagneticOne.com/ > Web development and design services > > -----Original Message----- > From: gawan [mailto:mail@gawan.net] > Sent: Saturday, February 08, 2003 1:15 AM > To: smarty-general@lists.php.net > Subject: [SMARTY] Replacing smarty variable from an associative array's > values > > > I have a book database and a field called country in my table. Countries > are coded with a two letter country code, e.g US, GB etc. > > I also have a long array of natural names for those codes, saved in a > file, like this: > > $ISO3166_CODE_TO_NATURAL = array( > "AF" => "Afghanistan", > "AL" => "Albania", > "DZ" => "Algeria", > "AS" => "American Samoa", > "AD" => "Andorra", > "AO" => "Angola", > "AI" => "Anguilla", > "AQ" => "Antarctica", > "AG" => "Antigua And Barbuda", > "AR" => "Argentina", > "AM" => "Armenia", > "AW" => "Aruba", > "AU" => "Australia", > ...etc. > > Now when I retrieve data for this table and want to display the long > name from the arrays, how should I do this without writing 200-300 lines > of {if } constructions? > > Country: {$ISO3166_CODE_TO_NATURAL[{$Country}] }won't > work, but what would? > > thank you > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.smarty.general (#7594) next »