I have built a Drupal 8 site, we are showing the user name and last name on a block, this is my code on preprocess from .theme file:
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$firstname = $user->get('field_firstname')->value;
$firstname = $firstname;
$variables['firstname'] = $firstname;
Then in the block im doing: Hello {{ firstname }}
And it shows the last user, not mine. When I do drush cr
then I get the correct name, why? How can I fix this and already display the right username?
public function getCacheMaxAge() { return 0; }