October 26, 2023
This is a followup to my post "Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8".
That post deals with core Drupal Date and Daterange fields. Recently I've been working on a site with events which use a Smart Date field. The Smart Date module offers many features that core Drupal date fields don't, such as recurrence.
Raw Smart…
Continue reading Print raw values from Smart Date fields in Twig templates - Drupal 8+
October 23, 2020
I wanted to change the format of the comment submitted timestamp on my blog, and figured it could be done in Twig - but nope. There's an active issue on Drupal.org to allow the format to be changed in the UI, but until that's done, you need to use a theme preprocess function.
function THEMENAME_preprocess_comment(&$variables) { $date_formatter = \Drupal::service('date.formatter…
Continue reading Change format of comment created date - Drupal 8 & 9
May 21, 2019
(Also see my post on how to get individual values from Smart Date fields).
I've been working on a site with events, and tearing my hair out over how to print formatted dates with the correct timezone value in Twig templates, specifically node.html.twig and views-view-fields.html.twig.
The issue was first, getting the formatted date to display in the template; and secondly, when I managed to get…
Continue reading Print formatted date with correct timezone from datetime or daterange field in node and Views templates - Drupal 8