fixed sample output of section in the docs and added this example as a unit test

This commit is contained in:
Simon Wisselink
2024-04-19 11:10:01 +02:00
parent 55799a9b65
commit 4549822cdd
2 changed files with 37 additions and 4 deletions

View File

@ -178,14 +178,14 @@ The above example will output:
</p>
<p>
name: Jack Jones<br />
home phone: 777-555-5555<br />
cell phone: 888-555-5555<br />
home: 777-555-5555<br />
cell: 888-555-5555<br />
e-mail: jack@myexample.com
</p>
<p>
name: Jane Munson<br />
home phone: 000-555-5555<br />
cell phone: 123456<br />
home: 000-555-5555<br />
cell: 123456<br />
e-mail: jane@myexample.com
</p>
```

View File

@ -148,4 +148,37 @@ class CompileSectionTest extends PHPUnit_Smarty
);
}
public function testNestedArrayAsLoopParameter()
{
$data = [
['name' => 'John Smith', 'home' => '555-555-5555',
'cell' => '666-555-5555', 'email' => 'john@myexample.com'],
['name' => 'Jack Jones', 'home' => '777-555-5555',
'cell' => '888-555-5555', 'email' => 'jack@myexample.com'],
['name' => 'Jane Munson', 'home' => '000-555-5555',
'cell' => '123456', 'email' => 'jane@myexample.com']
];
$this->smarty->assign('contacts',$data);
$result = $this->smarty->fetch('string:{section name=customer loop=$contacts}
name: {$contacts[customer].name}
home: {$contacts[customer].home}
cell: {$contacts[customer].cell}
e-mail: {$contacts[customer].email}
{/section}');
$this->assertEquals('name: John Smith
home: 555-555-5555
cell: 666-555-5555
e-mail: john@myexample.com
name: Jack Jones
home: 777-555-5555
cell: 888-555-5555
e-mail: jack@myexample.com
name: Jane Munson
home: 000-555-5555
cell: 123456
e-mail: jane@myexample.com
', $result);
}
}