Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

loop over users in select

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
PezerAFC
Smarty n00b


Joined: 04 Mar 2022
Posts: 1

PostPosted: Fri Mar 04, 2022 9:54 am    Post subject: loop over users in select Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Mar 07, 2022 5:08 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP