Views view unformatted and outputting taxonomy custom field

by Robbiegod   Last Updated August 13, 2019 22:07 PM - source

Original problem I had was I setup a taxonomy called Category. I added some vocabulary to my Category taxonomy. Some of the terms I added have contain spaces. The labels should have spaces so I want to keep them there. I want to remove the spaces from the Category name when they are output in the views view unformatted templated.

This would solve all of my problems if I can get those spaces out of the category names. I setup a custom field on the taxonomy terms to handle this, but I don't know how to access the custom fields of the taxonomy term from the views-view-unformatted.html.twig template. Is there a preprocesser function that can do this? Something where I can convert the category and just remove the spaces or change the value output from label to field_nospace_category ?

More experimenting

I setup a view of type page to display the articles in my content type Articles. I'm using using the unformatted list and I created a custom template called views-view-unformatted--my_view_id.html.twig. I see that this is the template that is outputting on my page.

I'm trying to output the taxonomy terms custom field as a class on the div that has {{ row.attributes.addClass(row_classes) }}

The div should end up looking like this:

...

I've tried several variations to try to get to the values. Inside of the for row in rows loop, i put:

{{ node.category.entity.field_category.value }}
{{ row.content['#node'].field_category.getValue().0.target_id }}
{{field_category}}
{{row.content['#elements'].field_category.getValue().0.target_id}}

I have tried to debug using Kint, Dump but my install keeps either throwing errors (out of memory) or blank white page.

Please help. Thank you in advance.



Related Questions


How to get taxonomy term name with url by tid

Updated May 03, 2018 08:07 AM



Taxonomy description for a custom taxonomy view

Updated June 30, 2017 01:07 AM