$xf.time not accessible in email template

stromb0li

Well-known member
Affected version
2.3.6
I'm trying to specify the following in an email template: {{date($xf.time,'M jS, Y g:i A')}}

Unfortunately, this yields: Dec 31st, 1969 6:00 PM

If I use the same in a public template, the date is rendered as expected (i.e. Apr 22nd, 2025 8:27 PM)
 
Last edited:
This is somewhat deliberate (only a handful of global data is available in mail templates), especially as they are rendered prior to being put on the queue and may not be sent until later. We could maybe add $xf.renderTime here to accommodate this.
 
We could maybe add $xf.renderTime here to accommodate this.
Hmm ... why do you want to introduce a new variable instead of just $xf.time?

It would be rendered at render time just like on public pages which might afterwards be stored in guest page cache for some time so at view time a couple minutes might have passed.
Emails might be send from queue some time after they have been rendered, so that is not much different IMHO:

PHP:
// accept that some dates might be slightly off

 
Just for clarity I suppose, as many are accustomed to thinking of it as the current/request time (even if that isn’t always true).

I guess it’s not even necessarily render time since it’s set during bootstrapping, but I don’t really care enough to bikeshed about it, $xf.time is ok for consistency too.
 
Back
Top Bottom