Oct 19, 2020 in Drupal 8

Snippet to dynamically add the year or a custom dynamic date to your page.html.twig file. In your mytheme.theme file, first add:

/**
 * Implements hook_preprocess_page().
 */
function mytheme_preprocess_page(&$variables) {
  $variables['year'] = date('Y', time());
}

Now, in your page.html.twig you can use:

{{ year }}
// Prints '2020'

 

Comments