簡體   English   中英

聰明的foreach迭代?

[英]foreach iteration in smarty?

我如何使用smarty在foreach循環的一次迭代中獲得兩條記錄? 或者我應該使用部分?

直接取自http://www.smarty.net/manual/zh/language.function.section.php#section.property.index.next上的文檔。 請確保閱讀文檔!

{* $rows[row.index] and $rows[row] are identical in meaning *}
<table>
  <tr>
    <th>index</th><th>id</th>
    <th>index_prev</th><th>prev_id</th>
    <th>index_next</th><th>next_id</th>
  </tr>
{section name=row loop=$rows}
  <tr>
    <td>{$smarty.section.row.index}</td><td>{$rows[row]}</td>
    <td>{$smarty.section.row.index_prev}</td><td>{$rows[row.index_prev]}</td>
    <td>{$smarty.section.row.index_next}</td><td>{$rows[row.index_next]}</td>
  </tr>
{/section}
</table>

上面的示例將輸出一個包含以下內容的表:

index  id    index_prev prev_id index_next next_id
0      1001  -1                 1          1002
1      1002  0          1001    2          1003
2      1003  1          1002    3          1004
3      1004  2          1003    4          1005
4      1005  3          1004    5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM