Forum
for loop in templates
Hi!
I'm working with the shop app, and in my case, for each room, the client specifies the max number of beds that the room can have. Like this:
<input type="number" id="perch_adultBeds" name="perch_adultBeds" value="2" required="" aria-required="true" class="number input-simple ">
Now I want to provide a select tag where the buyer picks the number of beds that he wants, so was wondering if perch allows me to do something like this:
<div class="col checkAdult searchItem">
<div style="margin-right: 0px;">
<select name="Adultos" style="height:44px;background:transparent;width: calc(100% - 5px);">
<perch:for id="adultBeds">
<option value="<perch:for id="perch_item_index"/>"><perch:for id="perch_item_index"/>Adultos</option>
</perch:for>
</select>
<img class="selectorArrow" src="./images/selectArrow.png" width="12px" height="6px">
</div>
</div>
I used <perch:for> just as an example, but the final result would be a select tag filled with all the possible options (in this case from 1 to 2). I couldn't find anything like this (I tried repeaters and blocks don't seem to be what im looking for ).
The only way within perch that I'm seeing is by fetching the number of beds beforehand, then in my php code generate the template, and then pass it as a variable to the template.
What would you advice?
thanks
Hello Gustavo,
If you use the input select field, your options can be like this:
You can generate the options in PHP with the
each
option:And then use
adultos_opts
as the value of theoptions
attribute:Thank you Hussein Al Hammad, I appreciate it :)