Page 1 of 1

HTML Block - Timebased content

Posted: Sun Jan 08, 2017 7:01 pm
by Njit
i'm using Smarty for my website. I'm trying to show some different content based on the time of day. But i'm doing something wrong with the logic i think.

I want to use these 3 timeframes (based on 24 hour period)

morning: 0600 - 1200
Afternoon: 1200 - 1800
Evening: 1800 - 0600

My HTML Block looks like this:

Code: Select all

<!-- It is now {$smarty.now|date_format:"%H:%M"} --> 

{if $smarty.now|date_format:"%H" >= 06 and $smarty.now|date_format:"%H" < 12 }{Showtime show='7'} 
{elseif $smarty.now|date_format:"%H" >= 12 and $smarty.now|date_format:"%H" < 18}{Showtime show='8'} 
{elseif $smarty.now|date_format:"%H" >= 18 and $smarty.now|date_format:"%H" < 06}{Showtime show='9'}{/if}

Re: HTML Block - Timebased content

Posted: Sun Jan 08, 2017 10:55 pm
by paulbaker
Your last elseif will never occur. Hours can never be bigger than 18 AND less than 6 at the same time.

You probably want to change the last AND to an OR.

Re: HTML Block - Timebased content

Posted: Mon Jan 09, 2017 5:27 am
by Njit
Feeling stupid. Changed it to OR.

Re: HTML Block - Timebased content

Posted: Mon Jan 09, 2017 12:56 pm
by chandra
Topic solved?

if yes please rename the topic ;) (add a [Solved] at the beginning).

Re: HTML Block - Timebased content

Posted: Mon Jan 09, 2017 2:23 pm
by Njit
I have seen it running ok during the morning and afternoon. will see what it will do in the evening and then rename the topic :-D

Re: HTML Block - Timebased content

Posted: Mon Jan 09, 2017 7:01 pm
by Njit
I see no option to edit/rename my startpost. But solved!

Re: HTML Block - Timebased content

Posted: Mon Jan 09, 2017 7:49 pm
by Rolf
You can accept the correct answer, topic will be marked solved automaticly

Re: HTML Block - Timebased content

Posted: Mon Jan 09, 2017 8:28 pm
by Njit
Don't see a option to accept an answer either :)