|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
PezerAFC Smarty n00b
Joined: 04 Mar 2022 Posts: 1
|
Posted: Fri Mar 04, 2022 9:54 am Post subject: loop over users in select |
|
|
Hello everyone, I'm pretty new to Smarty and in general I'm junior developer with my first job.
I inherited project that was done in Smarty and need to do some upgrades...
So I still have problems even with syntax and sometimes I found some solution but it's not working for me...
So I need idea and explanation how to write forexample foreach loop in SELECT, so that my options depends on how many users i have in db...
something like this
<select id="id_lokal" name="id_lokal" required>
<option value={USERS.id}>{USERS.name}</option>
</select>
I tried by creating LOOP..
<select id="id_lokal" name="id_lokal" required>
{LOOP: USERS}
<option value={USERS.id}>{USERS.name}</option>
{/LOOP: USERS}
</select>
But it creates new selects and in each select is new option |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Mar 07, 2022 5:08 am Post subject: |
|
|
The Smarty documentation will say to use the {foreach} structure:
Code: | <select id="id_lokal" name="id_lokal" required>
{foreach $USERS as $user}<option value={$user.id}>{$user.name}</option>{/foreach}
</select> |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|