Checking for custom view mode inside twig template! I am using {% if teaser %} .... {% endif %} To change structure of content type according to its view mode.

But it looks like I cannot check for custom view modes created using Drupal 8, Such as:

{% if medium_teaser %}
  &lt;div id="product-teaser"&gt;
     {{ content.field_image }}
     &lt;a class="buy-now-btn" href="{{ path('entity.node.canonical', {'node': 
     node.id}) }}"&gt;Buy now&lt;/a&gt;
  &lt;/div&gt;
{% endif %}


Is there a way to check for custom view modes in twig templates?
Assuming that's the node template, you have a view_mode variable available:

{% if view_mode == 'foo' %}

{% endif %}