RE: [SMARTY] Replacing smarty variable from an associative array's values
| From: | SavaJr | Date: | Sat, 08 Feb 2003 12:30:26 +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-7595@lists.php.net to get a copy of this message | ||
Hello Gawan, np
Actually that is the only workaround that is possible for now as I know.
That looks like hack to me - I'm using deep hashes like $var.$var1.$var2
often,
But don't know any other simple ways.
I'm joining this question to all smarty users.
---------------
Ruslan Savchyshyn
http://www.MagneticOne.com/
Web development and design services
-----Original Message-----
From: gawan [mailto:mail@gawan.net]
Sent: Saturday, February 08, 2003 2:32 PM
To: smarty-general@lists.php.net
Subject: Re: [SMARTY] Replacing smarty variable from an associative
array's values
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
>
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php