Re: [SMARTY] section and multiple arrays
| From: | messju mohr | Date: | Mon, 15 Nov 2004 11:37:19 +0000 |
| Subject: | Re: [SMARTY] section and multiple arrays | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11963@lists.php.net to get a copy of this message | ||
On Mon, Nov 15, 2004 at 04:32:24PM +0700, Valerie Delon wrote:
> Salut!
> I always got error message or even just white browser (without any output
> all) when I use section and associative&multiple arrays since most of the
> example from Manual about section always loop=integer values. (only one
> associative loop=$contacts, not integer but not with PHP code).
>
> What I was trying to do is :
>
> {* smarty *}
> {section name=customer loop=$contacts}
> name : {$contacts[customer].name}<br>
> home : {$contacts[customer].home}<br>
> cell : {$contacts[customer].cell}<br>
> e-mail : {$contacts[customer].email}<p>
> {/section}
>
> -----
>
> <?php
> include 'config3.inc.php';
> $smarty = new Smarty_try;
>
> $name = array('John Smith', 'Jack Jones', 'Jane Munson');
> $home = array('555-555-5555', '666-666-6666',
> '777-777-7777');
> $cell = array('111-111-1111', '222-222-2222',
> '333-333-3333');
> $email = array('john@smith.com', 'jack@jones.com',
> 'jane@munson.net');
> $contacts = array($name, $home, $cell, $email);
no, your array-structure doesn't reflect what you acces within your
{section} above.
build the array like:
$contacts = array();
$contacts[] = array('name' => 'John Smith', 'home' =>
'555-555-5555', 'cell' => '111-111-1111', 'email' =>
'john@smith.com');
$contacts[] = ...
note: you are still looping over an indexed array (and indexed array
of hash-arrays). you cannot (*never* *really* *believe me*) loop over
associative arrays with {section}.
> // print_r($contacts);die;
>
> $smarty->assign('contacts', $contacts);
> $smarty->display('section3.tpl');
> ?>
>
> and I got trigger error.
>
> Correction to this code above would be very welcome .
>
>
>
> Valérie Delon
> étudiante
>
> --
> On a besoin d'apprendre beacoup plus
> Quelqu'un croit c'est trop
> Mais j'crois que ce n'est pas assez
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php