1

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?

Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53

1 Answers1

1

I solved with a smarty foreach:

<select>
  {foreach item=category from=$categories}
    {html_options values=$category->getId() output=$category->getName()}
  {/foreach}
</select>
Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53