I am asking about styles in XF and having them affected by the current time. Not a person’s device or monitor.Probably nothing to do with CSS and everything to do with the device used to view your forum.
- That can happen on a desktop or laptop running Windows 10 if Night Light Settings are enabled and configured to display warmer colors in the evening.
- There is a similar setting for iPhones and iPads. No idea about whether Androids have this feature.
It's possible they use the user's set timezone in their preferences to conditionally load different CSS.I am asking about styles in XF and having them affected by the current time. Not a person’s device or monitor.
It's possible they use the user's set timezone in their preferences to conditionally load different CSS.
This happens to me automatically, after about 9 beers.9:00 PM in their selected time zone (under account preferences), some parts of the forum style get darker.
Because that's not what I'm looking for. Not to sound rude, but I'm just trying to do something different with a particular theme. I didn't post a question about XF styles and CSS for information about making a monitor darker, suggestions to have a completely separate theme, or condescending statements about what users might like. I'd like to put an if statement somewhere in the templates that allows me to control part of the theme. This is possible with vBulletin, so I'm trying to find a similar method with XenForo.Why don't you add a dark mode theme and let users choose. It might seem "cool" to have it change at night, but people tend to not like decisions like that made for them.
@Russ is THE cat to ask.Because that's not what I'm looking for. Not to sound rude, but I'm just trying to do something different with a particular theme. I didn't post a question about XF styles and CSS for information about making a monitor darker, suggestions to have a completely separate theme, or condescending statements about what users might like. I'd like to put an if statement somewhere in the templates that allows me to control part of the theme. This is possible with vBulletin, so I'm trying to find a similar method with XenForo.
time($xf.time, 'G')
will spit out the hour (0-23) for the visitor. You could do something like:<div class="{{ (time($xf.time, 'G') >= 21) ? 'dark-class' : '' }}">
<!-- ... -->
</div>
.dark-class
CSS class.Thanks, I'll start there and see what I can do. And thanks to everyone else who posted here even if I didn't go with your suggestions!time($xf.time, 'G')
will spit out the hour (0-23) for the visitor. You could do something like:
HTML:<div class="{{ (time($xf.time, 'G') >= 21) ? 'dark-class' : '' }}"> <!-- ... --> </div>
And then apply your styling with the.dark-class
CSS class.
Keep in mind that guests have the default timezone.
I'm assuming if it's JS it would use their computer time instead of XF profile time, so something like @Jeremy P said with $xf.time is probably closer.Not sure if this helps or not
time($xf.time, 'G')
will spit out the hour (0-23) for the visitor. You could do something like:
HTML:<div class="{{ (time($xf.time, 'G') >= 21) ? 'dark-class' : '' }}"> <!-- ... --> </div>
...and then apply your styling with the.dark-class
CSS class.
This would reset at midnight, but you can adapt it to also check if the time is before (less than) a certain hour as well. Keep in mind that guests have the default timezone.
<xf:if> {{ (time($xf.time, 'G') >= 21) ? 'dark-class' : '' }} <xf:else />
<xf:if is="$xf.time > $thread.post_date + 86400 * 3">
<!-- this will only be displayed after 3 days -->
</xf:if>
Timestamps are stored in Unix time, so I think something like this should work:
(86400 is the number of seconds in one day)HTML:<xf:if is="$xf.time > $thread.post_date + 86400 * 3"> <!-- this will only be displayed after 3 days --> </xf:if>
We use essential cookies to make this site work, and optional cookies to enhance your experience.