Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By riddick on
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
Share the screenshot.
Share the screenshot.
screenshot
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 }}
Try:
Updated
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...
Thanks. But it not helps. I
Thanks. But it not helps. I found method getDisplayName() but still is empty.
What template do you use?
What template do you use?
private-message.html.twig
private-message.html.twig
I wish custom this template - not only render {{ content }}
Did you rebuild the cache?
Did you rebuild the cache?
yes
yes
Solution
OK, I found solution - {{ content.owner.0['#user'].name.value }} this work correctly
My bad, I also, missed to ['
My bad, I also, missed to ['#user'] key.
I updated my answer.
can anyone explain
Can anyone please explain why this works but others don't. I didn't get the logic of it.
@Heya,
@Heya,
see the screenshot shared by @riddick:
https://www.studiografix.cz/images/kint.jpg
There is the ['#user'] array key, that we missed.
Can you please check this
Can you please check this link. This might be helpful for you
https://www.drupal.org/forum/support/module-development-and-code-questions/2011-11-11/working-with-associative-arrays