I’m a Drupal newbie and trying to achieve the below functionality:
In my Drupal site, user profile has username, role and category Taxonomy term. For every user these details are filled up. There is a message board setup to take comments from users. Everytime when a user comments, I would like to show as:
Submitted by: username, role, category at timestamp.
Rightnow, only the username is showing up. I tried to read the role and category fields through template_preprocess function as below:
/** * Implements hook_preprocess_HOOK() for comment.html.twig. */ function mytheme_preprocess_comment(array &$variables) { if (isset($variables['elements']['#view_mode'])) { $variables['view_mode'] = $variables['elements']['#view_mode']; } else { $variables['view_mode'] = 'default'; } dd($variables); }
But the dump does not show "category" field. Unsure what’s missing.
My comments.html.twig looks as below:
<div class="author-comments"> <p class="comment-submitted">{{ submitted }}</p> <div{{ content_attributes.addClass('content') }}> {% if title %} {{ title_prefix }} <h3{{ title_attributes }}>{{ title }}</h3> {{ title_suffix }} {% endif %} {{ content }} </div> </div>
any help on how to pull out the role and category field and plug into the twig template? Thanks!