According to my requirements I have to use views preprocess and views-view.html.twig
function MYTHEME_preprocess_views_view(array &$variables) {
$aliasManager = \Drupal::service('path.alias_manager');
if (isset($variables['rows'][0]['#rows'])) {
$nodeValues = [];
foreach ($variables['rows'][0]['#rows'] as $value) {
$nodeValue['created'] = $value['#row']->_entity->created->value;
$nodeValue['external_url'] = $value['#row']->_entity->field_url->uri;
$nodeValue['title'] = $title = $value['#row']->_entity->title->value;
$nodeValue['nid'] = $title = $value['#row']->_entity->nid->value;
$nodeValue['tid'] = $value['#row']->_entity->field_topic->entity->tid->value;
// section referenced to node
$nodeValue['section'] = $value['#row']->_entity->field_topic->entity->name->value;
$topics = "";
foreach($value['#row']->_entity->field_topic2 as $val){
$topics != "" && $topics .= ", ";
$topics .= $val->entity->name->value;
}
$nodeValue['topics'] = $topics;
$nodeValues[] = $nodeValue;
}
$variables['node_values'] = $nodeValues;
}
}
In twig file :
{% for value in node_values %}
<div class="link_full">
<div class="title"><a href="{{ value.external_url }}"> {{ value.title }} </a>
</div>
{% if logged_in %}
{% if 'premium' in user.getroles %}
<div class="link_details">
<div class="timestamp"><a href="{{ path('entity.node.canonical', {'node': value.nid}) }}">{{ value.created|date(format='y-m-d H:i') }}</a>
</div>
<div class="topics">{{ value.topics }}</div>
</div>
{% endif %}
{% endif %}
</div>
{% endfor %}
Out put is like below :
Everything is working fine but I need to create Links of terms in above screenshot. And in code its TOPICS in preprocess function.
I have tried various ways to create it as link but that does not work as it just print a tags as html but not links. Please suggest.
Thanks!