Smarty accessing array
{foreach from=$ncache.recmd name=spon key=k item=v}
{if ($smarty.foreach.spon.iteration%2) eq 0 || $smarty.foreach.spon.last}
<tr>
<td>
<label>
<input type="checkbox" name="iid[]" value="{$ncache.recmd[$k].item_id}"class="checkbox"/{$ncache.recmd[$k].model}{$ncache.recmd[$k].manufacturer}
</label>
</td>
<td>
<label>
<input type="checkbox" name="iid[]" 开发者_Python百科value="{$ncache.recmd[($k+1)].item_id}" class="checkbox"/>{$ncache.recmd[($k+1)].model}{$ncache.recmd[($k+1)].manufacturer}
</label>
</td>
</tr>
{/if}
{/foreach}
here is my smarty codes.
{$ncache.recmd[($k+1)].item_id}
{$ncache.recmd[$k+1].item_id}
{$ncache.recmd[$k++].item_id}
i tried to access to value but result is invalid i tried several form as above. but it still got problem.
Your question isn't clear, but I think I see what you are trying to do. I don't know what version of Smarty you're using, but I had similar difficulty with Smarty v2. I found that $smarty.foreach..iteration was going to be the next index (1-based indexing instead of 0-based). In that case, try this:
{foreach from=$ncache.recmd name=spon key=k item=v}
{if ($smarty.foreach.spon.index % 2) eq 0 || $smarty.foreach.spon.last}
<tr>
<td>
<label>
<input type="checkbox" name="iid[]" value="{$ncache.recmd[$k].item_id}"class="checkbox"/{$ncache.recmd[$k].model}{$ncache.recmd[$k].manufacturer}
</label>
</td>
<td>
<label>
<input type="checkbox" name="iid[]" value="{$ncache.recmd[$smarty.foreach.spon.iteration].item_id}" class="checkbox"/>{$ncache.recmd[$smarty.foreach.spon.iteration].model}{$ncache.recmd[$smarty.foreach.spon.iteration].manufacturer}
</label>
</td>
</tr>
{/if}
{/foreach}
精彩评论