There are a bunch of product images that are named same as SKU, so I'm just using field--commerce-product-variation--sku.html.twig to show them. All is fine.

I'd like to use the parent product image as fallback image for when the SKU image doesn't exist.

How do I access a parent product field from the product variation field template?

1 Answer 1


You'll get the variation object in element['#object']

{% set variation_object = element['#object'] %}
{% set product_object = variation_object.product_id.entity %}

then from product_object you can access the image field

  • That worked! Thanks. Then you can access image URI as product_object.field_product_img.0.entity.uri.0.value
    – betarobot
    Sep 28, 2021 at 15:49

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.