0

I have a content type which has a field that prints post related comments. My users have a couple of extra fields like name and last_name. Is there a possibility to add the first and last name of a user to a comment they've written, instead of just the username and profile picture?

function mysite_preprocess_node(&$variables) {
    $node = \Drupal::routeMatch()->getParameter('node');
    if($node && $node->getType() == 'berichten'){
        $variables['user'] = User::load($node->getOwnerId());
 
        $variables['field_reacties'] = $node->field_reacties->view('full');

    }

}

This is how I currently receive the comments view and show it to the related post.

1 Answer 1

0

I figured out that I can just receive user related fields from a comment by doing this {{ comment.getOwner.field_naam.value }} took me a while to figure that out, but it's handy for custom templates! :D

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.