0

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 %}
  <div id="product-teaser">
     {{ content.field_image }}
     <a class="buy-now-btn" href="{{ path('entity.node.canonical', {'node': 
     node.id}) }}">Buy now</a>
  </div>
{% endif %}

Is there a way to check for custom view modes in twig templates?

0

1 Answer 1

4

Assuming that's the node template, you have a view_mode variable available:

{% if view_mode == 'foo' %}

{% endif %}
2
  • instead of 'foo' Should i write the machine name of the view mode ???! like : "medium_teaser" Sep 26, 2017 at 13:55
  • Yes, that's correct
    – Clive
    Sep 26, 2017 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.