Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

draw current month in a table

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
mohrt
Administrator


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

PostPosted: Fri Sep 19, 2014 3:32 pm    Post subject: draw current month in a table Reply with quote

Smarty 3 code snippet to draw current month, highlight today:

Code:
{* draw current month, highlight today *}
{$dow = strftime('%w', strtotime('first day of this month'))} {* starting day of week *}
{$numdays = strftime('%d', strtotime('last day of this month'))} {* days in the month *}
{$today = strftime('%d')}
{$currday = 1}
<table>
    <tr>
        {for $x=0 to 34}
        <td{if $x==$today} class="today"{/if}>{if $x >= $dow && $x <= $numdays}{$currday++}{/if}</td>
        {if $x@iteration is div by 7} {* end of row, go to next row or end loop *}
            {if $currday < $numdays}</tr><tr>{elseif $currday >= $numdays}{break}{/if}
        {/if}
        {/for}
    </tr>
</table>


stylesheet:

Code:
.today {
   background-color: #7777ff;
}


Screenshot (styling not included, do that yourself):

Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks 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