Associative arrays
You can also reference associative array variables that are assigned from PHP by specifying the key after the "." (period) symbol.
Example 4-2. accessing associative array variables |
index.php:
$smarty = new Smarty;
$smarty->assign("Contacts",
array("fax" => "555-222-9876",
"email" => "zaphod@slartibartfast.com",
"phone" => array("home" => "555-444-3333",
"cell" => "555-111-1234")));
$smarty->display("index.tpl");
index.tpl:
{$Contacts.fax}<br>
{$Contacts.email}<br>
{* you can print arrays of arrays as well *}
{$Contacts.phone.home}<br>
{$Contacts.phone.cell}<br>
OUTPUT:
555-222-9876<br>
zaphod@slartibartfast.com<br>
555-444-3333<br>
555-111-1234<br> |
- 文章导航