Reputation: 87
Right now I'm developing a module for a prestashop website and I have a dropdown html select that I would like to fill from the database.
How can I do that?
Upvotes: 0
Views: 1186
Reputation: 87
Okay, so I found the answer by myself a few days after posting the answer, here's how to do it: Lets say I wanted to load my clients list from the database, in the hook method of the [module].php file I added a smarty variable:
$this->context->smarty->assign(array('clients' => Db::getInstance()->executeS('SELECT * FROM `clients_table`')));
and that would create a smarty variable that is accessible from the module's tpl.
Then the items in the cilent smarty variable can be added to the dropdown list with:
<select id="clients">
{foreach $clients as $client}
<option value="{$plan['id']}">{$client['name']}</option>
{/foreach}
</select>
Upvotes: 1