How do I get the vocabulary of a term inside an "article" type content type? I have a content type tagged with various vocabularies. Each vocabulary has terms which I want to style with particular colours based on the vocabulary. For example, say I have a "Fruits" vocab which has term 'apple' and 'banana' and a "veggies" vocab with 'onion' and 'carrot'. I want to colour the apple and banana tags RED and the onion and carrot tags BLUE *in same node. Say I've a content type "article" which is tagged with apple from the fruits vocab and carrot from the veggies vocab. 'apple' should have a RED background and 'carrot' and BLUE background. Another content node has apple and banana for tags and they should both be RED. 

I've found the following code, but it only works when the page I am viewing is the "apple" page - that is, I'm reading the page for the vocab term apple, NOT a content type tagged with apple. It DOESN'T work for tags in other content types and I'm failing miserably to find the right code.   

function MYTHEME_preprocess_field__entity_reference(&amp;$variables) {
  if (\Drupal::routeMatch()-&gt;getRouteName() == 'entity.taxonomy_term.canonical') {
  // load the term entity and get the data from there
  $term = \Drupal::routeMatch()-&gt;getParameter('taxonomy_term');
  $variables['vocab'] = $term-&gt;bundle();
  }
}


My theme has custom twig files for field--entity-reference.html.twig

and I'm trying to use the preprocess function above. Nothing I can find anywhere addresses this; what gives?
Adding the answer now. My final code in the field--entity-reference.html.twig file:

{% for item in items %}
  {% set mylabel %}
    {{ item.content }}
  {% endset %}
  {% set myclass %}
    {{ item.content['#options'].entity.vid.0.value['target_id'] }}
  {% endset %}
  {% set myclass = myclass|replace({'_':'-'}) %}
    &lt;div{{ item.attributes.addClass('taxonomy--item') }}&gt;
      &lt;a class="btn-small btn-primary tag-{{ myclass|trim }}" href="{{ item.content['#url'] }}" role="button"&gt;{{ mylabel|striptags }}&lt;/a&gt;
    &lt;/div&gt;
{% endfor %}


HERE is the code needed in a node to access the parent vocabulary of the taxonomy terms in the node. (That is, individual tags on a content type node).

item.content['#options'].entity.vid.0.value['target_id']


NOTE: This is on Drupal 8.5.3 and none of my "tags" have more than one parent.