I want to show a coupon code used on an order details page, but cannot seem to render it on a templates. Here are some things I have tried so far...

{% for coupon in order_entity.coupons %}
  {{ coupon.target_id }}
  {{ coupon.code }}
  {{ drupal_entity('commerce_promotion_coupon', coupon.target_id) }}
  {{ drupal_field('code', 'commerce_promotion_coupon', coupon.target_id) }}
{% endfor %}

The only thing that works is {{ coupon.target_id }} and it just prints out the id as a number. I thought I could use Twig Tweak to load the entity and get it that way, but that doesn't seem to work either.


  • Try to inspect the ID variable to make sure it contains an ID not render array. {{ dd(coupon.target_id) }}
    – ya.teck
    Nov 6, 2021 at 13:30

1 Answer 1


How I solved it ... (requires Twig Tweak module)

{% set coupon_entity = drupal_entity('commerce_promotion_coupon', coupon.target_id) %}
{{ coupon_entity['#commerce_promotion_coupon'].getCode }}

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.