XF 2.1 Is there any XF template syntax for formatting a date CTF?

Kevin

Well-known member
I currently have a widget that will display in my template, that's working fine, but is there any XF syntax I can use to format the date in different options?

For example, I'm using {{$thread.custom_fields.cv_tih_date|substr(0,4)}} to display just the YYYY of it but could I, in the template, format it is MM-DD-YYYY (instead of default YYYY-MM-DD) or even MMM DD, YYYY?
 
From the top of my head I think it was date_format($date, 'your format').
Thanks, Lukas. You may be thinking of the PHP command though as that gives an unknown function error when trying to use it in an XF template.

After some poking.... {{ date(date_from_format('Y-m-d', $thread.custom_fields.cv_tih_date), '') }} which will display the CTF date formatted using the date format defined in the ACP. Woohoo, midnight coffee breaks for the win! ☕😁

For anybody else working with CTF dates you want to use {{ date(date_from_format('Y-m-d', {CTF field name}), '{format}') }}, check the date function in XF\Language and you can see some of the pre-defined format options. In short, leave the format blank to use the XF defined format or use your own.

I'm my case I'm using both {{ date(date_from_format('Y-m-d', $thread.custom_fields.cv_tih_date), '') }} to display the full date in the same format as the rest of XF in some spots and then {{ date(date_from_format('Y-m-d', $thread.custom_fields.cv_tih_date), 'Y') }} for the spot where I want to display just the year.
 
Nesting functions seems pretty wrong to me. There is a single function that can do this, just check the templater for available functions.
 
Nesting functions seems pretty wrong to me. There is a single function that can do this, just check the templater for available functions.
The double-function is actually how the stock XF template is being used for displaying the CTF date types in custom_field_macros, the only difference being that the stock XF template is using {{ date(date_from_format('Y-m-d', $date)) }} with any format specified (so it uses the ACP defined format) while I needed to pass in a format for a few spots.
 
Back
Top Bottom