在smarty php中读出foreach的实际迭代?

时间:2014-04-24 09:52:03

标签: php foreach iteration smarty

我有一个问题;我想运行一个foreach-loop,并且在循环中应该是创建了实际迭代数的项目。

到目前为止我的代码:

{foreach from=$bilder item=item name=foreach_gallery}
    {capture assign=shopBild}
       <img src="{page_url page=$item}" border="0" alt="{$item->field.name}" title="{$item->field.title}" />
    {/capture}
    <tr>
        <td width="250">
            {$shopBild|max_image_width:160}<br/>
            <input type="text" size="2" name="pic_id{$smarty.foreach.foreach_gallery.iteration}" value="{$item->field.id}" readonly>
        </td>
        <td>
              {input type="text" name="articlename$smarty.foreach.foreach_gallery.iteration" title="Artikelbezeichnung:"}<br/>
              {input type="textarea" name="description$smarty.foreach.foreach_gallery.iteration" title="Artikelbeschreibung:"}<br/>
              {input type="text" name="articleid$smarty.foreach.foreach_gallery.iteration" title="Artikelnummer:"}<br/>
              {input type="text" name="prize$smarty.foreach.foreach_gallery.iteration" title="Preis:"}<br/>
        </td>
    </tr>
{/foreach}

它适用于

<input type="text" size="2" name="pic_id{$smarty.foreach.foreach_gallery.iteration}" value="{$item->field.id}" readonly> 

元素但不在{input ...}中。知道为什么它在第二种情况下不起作用以及我如何解决这个问题?

Greez Sebastian

2 个答案:

答案 0 :(得分:0)

您可以尝试:

<input type="text" name="articlename{$smarty.foreach.foreach_gallery.iteration}" title="Artikelbezeichnung:"> 

而不是:

{input type="text" name="articlename$smarty.foreach.foreach_gallery.iteration" title="Artikelbezeichnung:"}
希望我帮助你。

答案 1 :(得分:0)

我找到了解决方案如何在smarty-tag中执行smarty:

{input type="text" name="articlename`$smarty.foreach.foreach_gallery.iteration`" title="Artikelbezeichnung:"}

你需要用``

包装smarty-code