Render field with custom formatter on attribute change
Hi,
The normal way to render a commerce field would be to use this:
print render($content['product:field_my_image']);
Now I need to render it with a different formatter than the default and from what I know I need to use the field_view_field way to do that?
So far I have manage to render it with this:
$display = array('type' => 'custom_formatters_my_formatter'); // Formatter
$product_id = $node->field_product['und'][0]['product_id']; // Product ID
$product = commerce_product_load($product_id); // Load the product
$output = field_view_field('commerce_product', $product, 'field_my_image', $display);
print render($output);
This works nice except I don't know how to get the current ID ( [0] ) from the product that is currently beeing viewed.
Anyone have any suggestion how to solve this?
Kind regards, Mats