Show/hide views on content-type based on taxonomy-terms I have an activity-content-type with a taxonomy field, where I can choose from different taxonomy terms related to the activity. Now I have different views and I want to show the specific view on every activity-page, which is related to the chosen taxonomy-fields.

Lets say I have different bike-tours and diff. hikes (activities). Some are for beginners and some are for pros - some are for families and some are for couples and so on. Now I want to cross-link between the different activities and give more inspiration regarding suitable activities. If someone clicks on a bike-tour that is tagged with "beginners" and "families", drupal should show a view that offers other activities (bike-tours and hikes) that suit that criteria - also tagged with "beginners" and "families". Something like "Other familyfriendly beginner activities".

The machine names of the views don't relate with the chosen option at the moment. I would need to build a view for every combination at the moment - this is fine now (few combinations) but not scalable. I thought about combining all in one view (ideal), but couldn't find a solution yet.

Emanuel
The general idea is the following:

You create a custom block (via custom module).
You place it through the interace to be visible only on nodes of type "A".

The code checks the value of field_tags.


if it is "tag1" -> views_embed_view('test_view_1', 'block_1');
if it is "tag2" -> views_embed_view('test_view_2', 'block_1);


You can see code below:
    

namespace Drupal\form_overwrite\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'DefaultBlock' block.
 *
 * @Block(
 *  id = "default_block",
 *  admin_label = @Translation("Default block"),
 * )
 */
class DefaultBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {

    // Gets current node.
    $node = \Drupal::routeMatch()-&gt;getParameter('node');

    // Assuming only 1 value here.
    $tid = $node-&gt;get('field_tags')-&gt;getString();

    // If there are more values you have to loop through them. The format is.
    // $tid = $tag[0]['target_id'];

    // Loads the taxonomy term.
    $term = \Drupal::entityTypeManager()-&gt;getStorage('taxonomy_term')-&gt;load($tid);

    // Gets the label.
    $name = $term-&gt;label();

    // TODO: probably a better idea would be to use uuid of those terms, since
    // the names tend to change overtime.
    // TODO: Didn't test a case with translations.
    if ($name == 'tag1') {
      // Using the old but gold function views_embed_view() to get renderable array.
      // The render function spits the html, based on views_embed_view output.
      $content = render(views_embed_view('test_view_1', 'block_1'));
    }
    elseif ($name == 'tag2') {
      $content = render(views_embed_view('test_view_1', 'block_1'));
    }
    else {
      // Case where there is not tag.
      $content = '.....';
    }
    $build = [];
    $build['default_block']['#markup'] = render($content);
    // TODO: Remove it after development. It is used only to invalidate the cache.
    $build['#cache']['max-age'] = 0;

    return $build;

  }

}