2

I would like to display current date and time to the header section.

I am using a subtheme of Bartik. Any suggestions?

4

You can also add code page.html.twig as well.

For print only date use {{ "now"|date("m/d/Y") }}

More Details

http://twig.sensiolabs.org/doc/2.x/filters/date.html

https://stackoverflow.com/questions/17364206/symfony2-how-can-i-set-twig-dated-f-y-filter-to-output-months-in-swedish

  • Does this take into account site/user TZ settings, localization, and handle cache contexts properly? – mpdonadio Feb 9 '17 at 14:49
1

I can't comment directly on Smalution's answer, but can confirm that

{{ "now"|date("m/d/Y") }}

in twig DOES respect drupal user timezones. (Tested it in america/new york - 2:50, switched to america/edmonton - 12:50) as per mpdonadio's question.

0

For this you can create custom block and insert the PHP date function in it. (Install PHP module for insert php code in block or drupal site). Place this block on the header or where you want to place.

enter image description here

  • Does this take into account site/user TZ settings, localization, and handle cache contexts properly? – mpdonadio Feb 9 '17 at 14:51
  • 1
    Also not advised to inject PHP code as body content. – Kevin Feb 9 '17 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.