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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With