How do I use 2 different taxonomy view modes on one node page? On a node page I have a term reference field. This term contains 3 fields

For the term I've created a few view modes:


view_mode_first contains: field_1
view_mode_second contains: field_2, field_3


hook theme suggestions:

  function theme_theme_suggestions_taxonomy_term_alter(array &amp;$suggestions, array $variables) {
    $term = $variables['elements']['#taxonomy_term'];
    array_splice($suggestions, 2, 0, 'taxonomy_term__' . $term-&gt;bundle() . '__' . $variables['elements']['#view_mode']);
  }


node field template, where I'm displaying referenced terms:

  {% for item in items %}
      {% set first = item.content|merge({'#view_mode': 'view_mode_first'}) %}
      {{ first }}
  {% endfor %}


  {% for item in items %}
      {% set second = item.content|merge({'#view_mode': 'view_mode_second'}) %}
      {{ second }}
  {% endfor %}


But as a result I'm getting the same templates everywhere: taxonomy-term--name--view-mode-first.html.twig and not a taxonomy-term--name--view-mode-second.html.twig

I found that if I disable render cache in a settings.local file, both templates work:

$settings['cache']['bins']['render'] = 'cache.backend.null';


Is there possibility to disable render cache for specific node and/or fields?
The problem is that the view mode is also part of the cache keys and you would need to update them as well to avoid that both view modes are cached under the same cache id.


  Is there possibility to disable render cache for specific node and/or
  fields?


Yes, this is another possibility, you can disable caching of specific entities, in this case taxonomy terms, by removing the cache keys, which are in the #cache property. It's easier to manipulate this array in PHP, but this should also be possible in Twig. You can try to get #cache with the filter |without('keys') and merge it later with first and second.

You can also try to remove #cache completely from the second rendering

{{ second|without('#cache') }}


because all relevant cache metadata should bubble up already from the first rendering of the taxonomy term.