Monorail & NVelocity: primo e ultimo elemento di un ciclo foreach

datevenerdì 6 novembre 2009 alle 21.48  - posted by Manuel Scapolan in Castle Project

Può capitare alle volte di voler distinguere l'output di un foreach per il primo oppure l'ultimo elemento del ciclo, per fare questo in MonoRail il view engine NVelocity ci mette a disposizione la variabile $velocityCount che possiamo utilizzare nel seguente modo:

<table border="0" cellspacing="0">
   #foreach($item in $items)
      #if($velocityCount == 1)
      <tr class="first">
         <td>I'm the first row!</td>
      </tr>
      #elseif($velocityCount == $items.Count)
      <tr class="last">
         <td>I'm the last row!</td>
      </tr>
      #else
      <tr>
         <td> </td>
      </tr>
      #end
   #end
</table>

Fonte: Just in ram

Commenti chiusi

About me

manuel scapolanSono un consulente informatico. Nel 2004 terminati gli studi in Ingegneria Informatica (1° livello), ho iniziato come freelance collaborando con una ditta di consulenza informatica ed una agenzia di marketing e comunicazione nello sviluppo di applicazioni web. Attualmente divido il lavoro di sviluppatore e progettista web con attività di formazione nel settore della programmazione.
View Manuel Scapolan's profile on LinkedIn

Follow me on Follow manuelscapolan on Twitter

Calendario


<<  settembre 2010  >>
lumamegivesado
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Disclaimer

Eccetto dove diversamente specificato, i contenuti di questo sito sono rilasciati mediante:
creative commons
Attribuzione: Non commerciale
Condividi allo stesso modo. R.2.5

Books (a bit more about my library)

Domain Driven Design - Eric Evans Applying Domain-Driven Design and Patterns - Jimmy Nilsson Refactoring to Patterns - Joshua Kerievsky Design Patterns -  Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides Code Complete Second Edition - Steve McConnell Patterns of Enterprise Application Architecture - Martin Fowler Agile Principles, Patterns, and Practices in C# - Robert C. Martin xUnit Test Patterns - Gerard Meszaros Refactoring - Martin Fowler CLR via C# Second Edition - Jeffrey Richter Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries - Krzysztof Cwalina, Brad Abrams Don't make me think! - Steve Krug Bulletproof Ajax - Jeremy Keith

Manuel Scapolan Copyright © 2007 - 2010 - Tutti i diritti riservati - Powered by BlogEngine.NET 1.5.0.7 - silk icons by famfamfam - Time CET