I want to access 'name' key in the given image, but when I am trying with this author_picture['#user'].contents.name its showing nothing.

enter image description here

  • 1
    contents is the title of the debugger tab (not part of the variable), you just want author_picture['#user'].name
    – Clive
    Apr 11, 2018 at 19:02

1 Answer 1


Similar question for the node id from today Reason for adding .value to access node id?

Either add .value to the field name

{{ author_picture['#user'].name.value }}

or use a specific method if the entity provides one:

{{ author_picture['#user'].getdisplayname }}

It is preferable to use User:getDisplayName because it does extra processing:

By default, the passed-in object's 'name' property is used if it exists, or else, the site-defined value for the 'anonymous' variable. However, a module may override this by implementing hook_user_format_name_alter(&$name, $account).

Return value

string|\Drupal\Component\Render\MarkupInterface Either a string that will be auto-escaped on output or a MarkupInterface object that is already HTML escaped. Either is safe to be printed within HTML fragments.

  • {{ ...author_picture['#user'].name.value }} is showing error,
    – Ankit Jain
    Apr 12, 2018 at 11:35
  • {{ author_picture['#user'].name.value }} is working correctly, Thanks and pls edit the answer too
    – Ankit Jain
    Apr 12, 2018 at 11:36
  • I didn't know what variable you put in kint(), but it seems it is a top level variable, so we can remove the ...
    – 4uk4
    Apr 12, 2018 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.