0

I am trying to render the author Full Name and other authors customs fields information in comment.html.twig and node.html.twig. But not any of the fields that I made for users such as "First Name", "Last Name", and Auther UID etc. render in comments.

I tried with the following code for comment author

{{ comments.author.field-first_name.entity.value }}
{{ comment.author.user_picture.0.entity.uri.value }}
{{ comments.author.uid.entity.value }}

And, I tryed following code for node author:

{{ node.author.field-first_name.entity.value }} {{ node.author.user_picture.0.entity.uri.value }} {{ node.author.uid.entity.value }}

Any ideas, how do I render this info in comment template?

0

For Node:

{{ node.getOwner.field_first_name.value }}
{{ file_url(node.getOwner.user_picture.entity.fileuri) }}
{{ node.getOwner.uid.value }}

For Comment:

{{ comment.getOwner.field_first_name.value }}
{{ file_url(comment.getOwner.user_picture.entity.fileuri) }}
{{ comment.getOwner.uid.value }}
  • Thank you, it's working fine. But the "file_url" doesn't work for the default image path. Any idea how do I get the default image path? – Punya Ruchal Mar 18 at 12:13
0

To find a solution I would first check, if the information I want to display is in the actual render array. You can do this by using a variable dump.

{{ dump(comments|keys }}

or

{{ dump(comments.author|keys }}

(If you have devel with kint installed, you can use this vor variable dump.)

Now you can look: If your first-name field is not in the render array, then no template will be possible to show it.

To get custom pieces of information in your render array, this answer my perhaps helpful to you: How do I print custom user fields?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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