I am trying to get to the field_news_type term_id/label. I can print the field and I get the term label. Need guideance to be able to select which one I want to use.

{{ fields.field_news_type.content }} //prints the term 'Grid 2' which is correct.

I am trying to get either the label or term_id, so I can do a conditional. The below does not work. I have tried many variations. I have not found an answer that has produced a working result. Can someone guide me to finding the correct way to print this out in a views template page?

{% if fields.field_news_type.target_id == '2871' %}

I can use this for a node template page and it works...but not in the views twig file.

{% if content.field_research_focus_areas['#items'].getValue() %}

1 Answer 1


The code doesn't match the template, it's more likely from a views-view-fields.html.twig template. Then you could configure a separate field in Views UI to produce the output you want. Views fields are not a 1:1 match of entity fields, you can rewrite the entity content to whatever you want. Most times it's a better idea to put Twig in Views UI and not in Views templates.

If you really want to access raw field values, don't use the output of Views field plugins. Access field values directly through the node object:

{{ row._entity.field_ref.target_id }}

More info Access row value in template_preprocess_views_view_fields(&$variables)

  • Thank you for that. I will go check it out. My goal is to have the template show a specific piece of content in a views block, like a selected news item. If if has the tax term, then...
    – timwhelan
    May 4, 2021 at 12:39

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.