I have created some media image attributes to show in a couple of places on the product page.
They work fine if an image is selected for each of them but if not the page doesnt load correctly it seems to stop loading at more information.
If I go into the product and select an image for the attributes, save, then unselect and save again the product opens but can't do this for every product.
It works fine with new text attributes its only empty media image attributes.
This is for magento 2.1.12.
The code for pulling each the attributes is
<div class="col-sm-4">
<img src="<?php
$productImageAttr = $product->getCustomAttribute( 'productfeature2' );
$productImage = $this->helper('Magento\Catalog\Helper\Image')
->init($product, 'productfeature2')
->setImageFile($productImageAttr->getValue());
echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" /></p>
</div>
Is there a way to code this to skip any empty attributes from displaying?