Reputation: 10071
I would like to print out a different string of text based on the current day of the week. Any advice?
Am I on the right track with this:
{if $current_timestamp|date_format:"%A" == 'Monday'}
Monday
{elseif $current_timestamp|date_format:"%A" == 'Tuesday'}
Tuesday
{elseif $current_timestamp|date_format:"%A" == 'Wednesday'}
Wednesday
{elseif $current_timestamp|date_format:"%A" == 'Thursday'}
Thursday
{elseif $current_timestamp|date_format:"%A" == 'Friday'}
Friday
{else}
Weekend
{/if}
This is currently working for me but I was wondering if there's a more efficient way.
P.S. I won't be printing out the name of the day of the week, that's just my example.
Upvotes: 3
Views: 1192
Reputation: 13557
you should learn to "cache" your values:
{assign var="weekday" value=$smarty.now|date_format:"%u"}
{if $weekday == 1} Monday
…
{elseif $weekday == 7} Sunday
{/if}
Upvotes: 5