I wasted hours trying to do this which was relatively easy in drupal 7. What is the right way to get the value from user logged in (current user) fields and print it in TWIG templates? Not in user profile TWIG, but in BLOCK and PAGE TWIGs.
I was trying to use the entityTypeManger like the code bellow, but no success.
use DrupalCoreEntityEntityTypeManager; use DrupaluserEntityUser; $user_id = Drupal::currentUser()->id(); $user_entity = Drupal::entityTypeManager()->getStorage('user')->load($user_id); $variables['field_custom'] = $user_entity->field_custom->value;
So in my TWIG files I could print
{{ field_custom }}
I would like go ahead and make it harder… Since the field custom is avalaible, how can I print the field options when this field is taxonomy term? To get the term ID or URL for example. Something like this:
{{ field_custom|tid }}