I'm new to Drupal (8) and have no PHP experience, but I've managed to get this interesting CMS doing just about everything I need by playing with Twigs.

I cannot for the life of me figure out how to get a Page's "Last Saved" date to render in the footer block though.

In the Node twig I can add this, and it works perfectly:

{{ node.changed.value|date("d/m/Y H:i") }}

But in the region--footer.html.twig (which is an included block at the base of every page on the site, and where I wish to render this information) all I get back, from every combination I try, is the current date/time of when the page loads in the browser. Actually, i think it is the current server time.

Obviously there's something I just don't get about how Drupal works!

Can anyone offer a newbie some help in language I might understand?

Cheers, mrEdge

  • Depending on which template file you are in, there are different variables available. The node variable is typically available in page.html.twig and node.html.twig, but not in region.html.twig or block.html.twig. The available variables are documented in the template files of the core theme stable
    – Hudri
    Jul 26, 2018 at 5:53
  • So I gathered, but what's the workaround @Hudri? How can I globally, for all node types (articles, basic page, front page, taxonomy pages) render a footer that includes the Last Saved date?
    – mrEdge
    Jul 26, 2018 at 6:05

1 Answer 1


I think you can add to the yourtheme.theme file next thinks;

function yourtheme_preprocess_region(&$vars) {
  $vars['node'] = \Drupal::routeMatch()->getParameter('node');

and afterwards in your twig template each region will have available variable node.

{% if node %}
  {{ node.changed.value|date("d/m/Y H:i") }}
{% endif %}

Don't forget to clear cache.

  • Hey Alex, Thank you. I've found the .theme file and have inserted the function above. How do I name the "yourtheme_preprocess_region"?
    – mrEdge
    Jul 26, 2018 at 6:20
  • I had a guess and oh my goodness, it's working! IT IS WORKING! Thank you Alex!!!!
    – mrEdge
    Jul 26, 2018 at 6:29
  • @mrEdge this is great!! no problems Jul 26, 2018 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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