I've been following this discussion: How to apply an image style based on a condition (a date for ex.)? but unfortunately it has not been a success.

I would like to have the image to change based on a boolean field type being checked or not. When I check the On Sale checkbox, I would like the product image to be displayed with a different image-style.

My boolean field is named field_commerce_saleprice_on_sale. 1st image style is product_grid. 2nd image style on_sale. In node--product.tpl.php I found the line

Thanks in advance for your help.


1 Answer 1


If you want to do it in template file, you can access your boolean variable using $node object. You can do following way :

if ($node->field_boolean[LANGUAGE_NONE][0]['value']) {
  print theme('image_style', array('path' => $node->field_image['und'][0]['uri'], 'style_name' => 'style1_name'));
else {
  print theme('image_style', array('path' => $node->field_image['und'][0]['uri'], 'style_name' => 'style2_name'));

Or :

If you are using panels, then you can use visibility rule to the fields by adding it twice with different image style.

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.