cancel
Showing results for 
Search instead for 
Did you mean: 

How to install iframe in magento 2 instead of product photos

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to install iframe in magento 2 instead of product photos

I need to place an iframe instead of photos on a product page in Magento 2. For product photos to be in the iframe

1 REPLY 1

Re: How to install iframe in magento 2 instead of product photos

Hello @anna_moroz ,

You can take help from https://webkul.com/blog/create-and-manage-product-file-type-attribute-in-magento-2/ this blog to create a video type attribute of product and in your custom theme override gallery.phtml by Magento_Catalog\templates\product\view\gallery.phtml and use the below code:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var $block \Magento\Catalog\Block\Product\View */
?>
<?php $_product = $block->getProduct();
$imageHelper = \Magento\Framework\App\ObjectManager::getInstance()
				->get(\Magento\Catalog\Helper\Image::class);
$path = $this->getUrl('pub/media/catalog/product/file') ;
$path = $path.$_product->getData('video'); ?>
<?php if($_product->getData('video')) { ?>
<video height="auto" data-autoplay="true" autoplay="true" loop="true" muted="" playsinline >
  <source src="<?php echo $path; ?>" type="video/mp4">
  <source src="<?php echo $path; ?>" type="video/ogg">
</video>
<?php } else { ?>
<img src="<?php echo $imageHelper->getDefaultPlaceholderUrl('image'); ?>"/>
<?php } ?>

NOTE: I have used attribute name as "video" so I am using $_product->getData('video')

If this helps you, please accept it as solution and give kudos.

Regards.