Posted in ECSHOP, 程序开发

ecshop中调用smarty的foreach-iteration函数

ken 2009-11-12 Hit: 751
  ecshop中的模板技术确实不错,ecshop的smarty也写的很好,foreach标签是ecshop中smarty用的最多的一个标签了。而foreach中的iteration非常有用。
 
    iteration其实是foreach循环中的下标,而且从1开始.直接循环。所以在ecshop销售排行中,很多人用这个来区分销售的图标.他是foreach下name的键值.{foreach name=top_goods from=$top_goods item=goods}
 
   <meta http-equiv="Content-Type" content="text/html; charset=gbk">
<div class="mod2">
 <h1><span class="left"></span><span class="right"></span>销售排行</h1>
 <!-- {foreach name=top_goods from=$top_goods item=goods}-->
  <ul class="top10 clearfix">
 <li><img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" />
 <!-- {if $smarty.foreach.top_goods.iteration<2}-->
 
    <table width="185" border="0">
  <tr>
    <td><a href="{$goods.url}" target="_blank"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="topimg" height="80px" width="80px" /></a></td>
    <td>售价:<font class="f1">{$goods.price}</font></td>
  </tr>
</table>
 
 
 
 <!-- {/if} --> 
       <{if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}>
      <a href="{$goods.url}" title="{$goods.name|escape:html}" target="_blank">{$goods.short_name}</a><br />
 
      </li>
   <div style="clear:both;"></div>
    </ul>
  <!-- {/foreach} -->
</div>
 
    这个是ecshop销售排行的模板,他通过巧妙使用foreach来实现了图标的对应.><img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" />

随机日志

欢迎订阅: Google Reader | 鲜果 | 抓虾 | 九点 | QQ邮箱 | 有道 | 更多

1 条评论

  • (Required)
  • (Required, will not be published)