How to print a taxonomy term's field value alongside a Views grouping header?

by Nick Hope   Last Updated January 10, 2018 18:07 PM

In Drupal 8.4.4 I have a "Living Things" taxonomy vocabulary. One field on the terms in the vocabulary is "Most Common Name", with machine name field_most_common_name. On my "Animalia" term its value would be "Animal".

In Views, I have a "Taxon Media" view which lists media related to the taxonomy term. I display it in a block on the taxonomy term's pages themselves (not on nodes). In the view I group media by another field, "Primary Taxon", which is a reference to the term. It prints on the page as the grouping heading (e.g. "Animalia").

How can I print the value of my "Most Common Name" field next to that title? i.e. "Animalia Animal".

I have made a template, views-view-grouping--taxon-media.html.twig, cloned from the one in the Classy template, tested that works, then added the 4th line and tried a few other things such as content.field_most_common_name, but cannot get the field's value to display:

<div class="view-grouping">
  <div class="view-grouping-header">
    {{ title }}
    {{ field_most_common_name }}
  <div class="view-grouping-content">{{ content }}</div>

If it helps, this is the output of {{ dump(_context|keys) }} at the top of that template:

0 => string 'view' (length=4) 1 => string 'grouping' (length=8) 2 => string 'grouping_level' (length=14) 3 => string 'rows' (length=4) 4 => string 'title' (length=5) 5 => string 'theme_hook_original' (length=19) 6 => string 'attributes' (length=10) 7 => string 'title_attributes' (length=16) 8 => string 'content_attributes' (length=18) 9 => string 'title_prefix' (length=12) 10 => string 'title_suffix' (length=12) 11 => string 'db_is_active' (length=12) 12 => string 'is_admin' (length=8) 13 => string 'logged_in' (length=9) 14 => string 'user' (length=4) 15 => string 'directory' (length=9) 16 => string 'content' (length=7) 17 => string '#cache' (length=6) 18 => string 'theme_hook_suggestions' (length=22) 19 => string 'theme_hook_suggestion' (length=21)

Related Questions

Taxonomy page variables giving empty values

Updated August 14, 2018 10:07 AM

Taxonomy Term Page Show Children Terms & Nodes

Updated October 25, 2017 15:07 PM

Unnecessary showing admin content in main theme

Updated January 04, 2018 20:07 PM

Taxonomy page accessing terms in header

Updated September 03, 2018 03:07 AM