How to check the machine name of the product type?

209 views Asked by At

I have the TWIG code below that works. It checks that "Produit" is in the name of the product type.

My problem :

I want it to check the machine name of the product type (not the title of the machine name), in my case product

How do you do that ?

  {% if 'Produit' in message.field_product_reference.entity.field_pop_up_product_reference.entity.type.entity.label %}
    <a href="{{ path('entity.commerce_product.canonical', {'commerce_product': message.field_product_reference.entity.field_pop_up_product_reference.entity.id}) }}" title="{{ message.field_product_reference.entity.field_pop_up_product_reference.entity.title.value }}" class="stretched-link"></a>
  {% else %}
    <a href="{{ path('entity.commerce_product.canonical', {'commerce_product': message.field_product_reference.entity.id}) }}" title="{{ message.field_product_reference.entity.title.value }}" class="stretched-link"></a>
  {% endif %}
1

There are 1 answers

1
dotist On

Try entity.bundle instead of label : )