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

Section index value

 
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 -> General
View previous topic :: View next topic  
Author Message
aapje
Smarty Rookie


Joined: 18 May 2010
Posts: 5

PostPosted: Thu Dec 02, 2010 2:18 pm    Post subject: Section index value Reply with quote

Code:

{section name=maanden start=1 loop=12 step=1}
   <tr>
      <td>{$smarty.section.maanden.index|date_format:"F"}</td>
   </tr>
{/section}


Why on earth does this display:

January
January
January
January
January
January
January
January
January
January
January

Somehow it keeps using the index 1 in every loop. But when I print the index value it says 0 till 12.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Dec 02, 2010 2:29 pm    Post subject: Reply with quote

date_format expects a timestamp or date string, not an integer.
Back to top
View user's profile Send private message Visit poster's website
aapje
Smarty Rookie


Joined: 18 May 2010
Posts: 5

PostPosted: Thu Dec 02, 2010 2:34 pm    Post subject: Reply with quote

mohrt wrote:
date_format expects a timestamp or date string, not an integer.


Facepalm, just found out myself where I was going wrong Embarassed
Back to top
View user's profile Send private message
aapje
Smarty Rookie


Joined: 18 May 2010
Posts: 5

PostPosted: Thu Dec 02, 2010 2:56 pm    Post subject: Reply with quote

If anyone needs to loop through all months of the year:

php:
Code:

$months = array();
for ($i = 1; $i <= 12; $i++) {
   $months[$i] = strftime("%B", mktime(0,0,0, $i, 1));
}


smarty:
Code:

$smarty->assign("months", $months);

{foreach name=months from=$months item=month}
   <tr>
      <td>
         {$month}
      </td>
   </tr>
{/foreach}
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 -> General 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