2010-04-19 5 views
1

Comment puis-je obtenir deux enregistrements dans une itération de boucle foreach en utilisant smarty? OU devrais-je utiliser la section?foreach itération dans smarty?

+0

Que voulez-vous dire exactement deux dossiers? Pouvez-vous fournir beaucoup plus de détails? – webbiedave

Répondre

0

Pris directement à partir de la documentation sur http://www.smarty.net/manual/en/language.function.section.php#section.property.index.next. S'il vous plaît assurez-vous de lire la documentation!

{* $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> 

L'exemple ci-dessus sortie une table contenant les éléments suivants:

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