Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Counter in foreach einbauen

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
serecords
Smarty n00b


Joined: 25 May 2013
Posts: 3

PostPosted: Sat May 25, 2013 10:09 am    Post subject: Counter in foreach einbauen Reply with quote

Hallo

ich habe folgende foreach Abfrage in meinem Template:
Code:

{foreach name=UserLevelStatistik item=LevelStatistik from=$UserLevelStatistik}
   <tr>
      <td style="vertical-align: middle; text-align: center;"" >
         {$UserLevelPlatzierung.0++}. <img src="{$SITEPATH}/Pfad/zum/Bild" style="vertical-align: middle;" />
         <br />
         {$LevelStatistik.Name}
         <br />
         {$UserLevelZeit.0++}
      </td>
   </tr>
{/foreach}


Nun an dieser Stelle
Code:
{$UserLevelZeit.0++}
möchte ich einen Counter einbauen, dies funktioniert allerdings nicht mit 0++.
Es soll bei jedem Durchlauf (es werden 5 Durchläufe sein), die Zahl hinter $UserLevelZeit von 0 beginnend um 1 vergrößert werden.

Mein Array, das ich hier darstellen möchte, ist folgendermaßen aufgebaut, daher auch die Zahlen von 0-4:
Code:
Array
(
    [0] => 101 Stunden und 25 Minuten
    [1] => 100 Stunden und 4 Minuten
    [2] => 90 Stunden und 26 Minuten
    [3] => 84 Stunden und 58 Minuten
    [4] => 80 Stunden und 55 Minuten
)


Wie kann ich dies nun umsetzen?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat May 25, 2013 12:29 pm    Post subject: Reply with quote

{foreach} hat breits eingebaute Schleifenzähler. (index bzw. iteration)

Siehe http://www.smarty.net/docs/en/language.function.foreach.tpl
Beispiel 7.34 und 7.35

Da Du noch die syntax von Smarty2 verwendest müsstest Du eventuell auch hier schauen
http://www.smarty.net/docsv2/en/language.function.foreach.tpl
Back to top
View user's profile Send private message
serecords
Smarty n00b


Joined: 25 May 2013
Posts: 3

PostPosted: Sat May 25, 2013 3:41 pm    Post subject: Reply with quote

Hallo,

Vielen Dank für den Hinweis, dass ist natürlich praktisch.
Ich werde es heute nicht mehr versuchen können, aber morgen werde ich dann berichten.
Back to top
View user's profile Send private message
serecords
Smarty n00b


Joined: 25 May 2013
Posts: 3

PostPosted: Sun May 26, 2013 2:16 pm    Post subject: Reply with quote

Danke nochmal, hat wunderbar geklappt.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP