I wish customize template for private message. In template I print with kint

{{ kint(content.owner.0) }}

and I got this

content.owner.0 array(6)
→'#user' => Drupal\user\Entity\User(28)
contentsStatic class properties (14)Iterator contents (20)Available methods (154)
→protected values -> array(17)
→'uid' => array(1)
'x-default' => string(1) "1"
→'uuid' => array(1)
'name' => array(1)
'x-default' => string(6) "username"

how can I move to "name" value?

Comments

wombatbuddy’s picture

Share the screenshot.

riddick’s picture

Screenshot is here

sorry but I dont see button for upload image to drupal

if I use {{ content.owner.0['#user'] }} it not work, the same if {{ content.owner.0.user }}

wombatbuddy’s picture

Updated

{{ content.owner.0['#user'].getUsername() }}

It seems you have problem because try to use protected property.
Open 'Available method tab' (click on it) and find method you needed. Also, you can investigate the API docs for the class you are unteresting in, like this: https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Entity%2...

riddick’s picture

Thanks. But it not helps. I found method getDisplayName() but still is empty.

wombatbuddy’s picture

What template do you use?

riddick’s picture

private-message.html.twig

I wish custom this template - not only render {{ content }}

wombatbuddy’s picture

Did you rebuild the cache?

riddick’s picture

yes

riddick’s picture

OK, I found solution - {{ content.owner.0['#user'].name.value }} this work correctly

wombatbuddy’s picture

My bad, I also, missed to ['#user'] key.
I updated my answer. 

{{ content.owner.0['#user'].getUsername() }}
Heya’s picture

Can anyone please explain why this works but others don't. I didn't get the logic of it.

wombatbuddy’s picture

@Heya,
see the screenshot shared by @riddick:
https://www.studiografix.cz/images/kint.jpg
There is the ['#user'] array key, that we missed.

Heya’s picture