- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019
05:05 AM
09-30-2019
05:05 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2019
10:38 PM
09-30-2019
10:38 PM
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.