0

I have created a custom widget and now, I am trying to display product images enter image description here

Something like in the Product view page.

On catalog_product_view.xml it calls /vagrant/www/vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml

How can I call gallery.phtml in my custom phtml file?

2
  • You could try embedding it with PHP?: <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Catalog::gallery.phtml")->toHtml() ?> You will probably have to create an override for the file in Magento_Catalog/templates/product/view/gallery.php and call it from there Oct 27, 2020 at 17:25
  • and how can I pass the variable (the product id)? could you please give me an example? Thank you Oct 28, 2020 at 17:28

1 Answer 1

0

Edit your catalog_product_view.xml file, move the media gallery block to your custom block

<move element="product.info.media" destination="your_block_name" as="product.info.media" />

After that you can call media gallery block to your custom phtml file like below

<?= $block->getChildHtml('product.info.media') ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.