|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I want to achieve the following process in the smarty
for $item['menu' . $i] one i should be able to get the value using loop.index, but without any luck. any is appreciated. <?php for ($i = 1; $i <= 30; $i++) : ?> <tr> <th><?= $i ?></th> <td><input type="text" class="text1" name="menu<?= $i ?>" value="<?= $item['menu' . $i] ?>"/></td> <td><input type="text" class="price" name="menu<?= $i ?>_price" value="<?= $item['menu' . $i . '_price'] ?>"/></td> </tr> <?php endfor; ?> ====SMARTY==== {section name=loop start=1 loop=30} <tr> <td>{$smarty.section.loop.index}</td> {assign var="i" value=$smarty.section.loop.index} <td><input type="text" class="text1" name="menu{$i}" value="{$item}{'menu$i}"/></td> </tr> {/section} |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Nov 13, 3:06 am, "sksksk" <dkfjld...@dfd.com> wrote:
> I want to achieve the following process in the smarty > for $item['menu' . $i] one i should be able to get the value using > loop.index, but > without any luck. > > any is appreciated. > > <?php for ($i = 1; $i <= 30; $i++) : ?> > <tr> > <th><?= $i ?></th> > <td><input type="text" class="text1" name="menu<?= $i ?>" > value="<?= $item['menu' . $i] ?>"/></td> > <td><input type="text" class="price" name="menu<?= $i ?>_price" > value="<?= $item['menu' . $i . '_price'] ?>"/></td> > </tr> > <?php endfor; ?> > > ====SMARTY==== > {section name=loop start=1 loop=30} > <tr> > <td>{$smarty.section.loop.index}</td> > {assign var="i" value=$smarty.section.loop.index} > <td><input type="text" class="text1" name="menu{$i}" > value="{$item}{'menu$i}"/></td> > </tr> > {/section} I think this will work {section name=loop start=1 loop=30} <tr> <td>{$smarty.section.loop.index}</td> {assign var="i" value=$smarty.section.loop.index} {assign var="arrayIndex" value="menu". $smarty.section.loop.index."_price"} <td><input type="text" class="text1" name="menu{$i}" value="{$item.$arrayIndex}"/></td> </tr> {/section} Store array index in variable and then access it. |
|
![]() |
| Outils de la discussion | |
|
|