Reputation: 12616
I want to create a select dropdown list populated with the Categories array that I put inside an array.
$contents
is an array whose entries are automatically assigned in smarty.
foreach ($contents as $key => $value) {
$this->_smarty->assign($key, $value);
}
Controller.php:
private $contents;
public function createStart() {
$categories = $service->listCategories();
$this->contents['categories'] = $categories;
return 'documentsform-view';
}
html view:
<select>
{html_options options=$categories}
</select>
This doesn't work.
Categories are objects. I want my options values to take each category ID, and to show each category name. How can I do that?
Upvotes: 1
Views: 605
Reputation: 12616
I solved with a smarty foreach
:
<select>
{foreach item=category from=$categories}
{html_options values=$category->getId() output=$category->getName()}
{/foreach}
</select>
Upvotes: 1