问题描述
我有下面的 TWIG 代码可以使用。它检查“产品”是否在产品类型的名称中。
我的问题:
我希望它检查产品类型的机器名称(不是机器名称的标题),在我的例子中是 product
你是怎么做到的?
{% 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 %}
解决方法
试试 entity.bundle
而不是 label
: )