Get logged in user's username as twig variable
You would have to target a specific one. All twig templates is not possible because of caching. Many page elements don't get rebuilt on every request and they will display the wrong user.

And if you try to remove caching from all elements, your site would be very slow.

If you add this to a specific twig template, then you can adjust the cache context of this render element:

function MYTHEME_preprocess_HOOK(&amp;$variables) {
  $variables['currentusername'] = \Drupal::currentUser()-&gt;getUsername();
  $variables['#cache']['contexts'][] = 'user';
}


Where HOOK is your template type.