I want to create an extension that will give shop owners ability to edit their product image. So I understand I need this template Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml

I have tried the following guide http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/templates/template-walkthrough.html with no success.

How can I extend this template in my extension? What are my options?

  • The link you posted shows you the most direct and simplest way to "extend" (really "override") an existing template with your own. I'd suggest checking to see that you've correctly created the appropriate folder hierarchy in your custom module to match what the devdocs state. Furthermore, you might want to check the basis...is your module enabled? Have you cleared all the generated files (or cleared cache) before loading that page (to verify your template is getting loaded instead of the core template)?
    – ryanF
    Jan 15 '17 at 15:07
  • This is my path: magento\htdocs\app\design\adminhtml\Amasty\HelloWorld\ProductVideo\templates\helper\gallery.phtml Should this work?
    – Roninio
    Jan 15 '17 at 15:10
  • @Roninio you create a custom module or custom admin theme? Jan 15 '17 at 15:29
  • Sorry for the confusion. I want to set a custom module, as i want to be able to make logical changes.
    – Roninio
    Jan 15 '17 at 15:31
  • @Roninio There's some confusion here. After revisiting that link you posted, that method is specifically for using a custom theme, not a custom module. If you were to use a custom theme to override the vendor/magento/module-product-video/view/adminhtml/templates/helper/gallery.phtml should be magento\htdocs\app\design\adminhtml\Amasty\HelloWorld\Magento_ProductVideo\view\adminhtml\templates\hel‌​per\gallery.phtml . Otherwise, you'd use something like what @Khoa TruongDinh suggested. Furthermore, the Magento_ProductVideo module uses an observer to set the template to begin with.
    – ryanF
    Jan 16 '17 at 20:48

As far as I know, there are some ways:

1) We can override the Block. In your custom block, we need to set the template variable: (not recommend)

 * @var string
protected $_template = 'Vendor_Module::catalog/product/helper/gallery.phtml'; // Your custom template.

2) In case, we can set the template via layout (recommended way)

For example, we need to set the custom Add to Card template.


<referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Module::cart/item/configure/updatecart.phtml</argument>

In your case, I search throught the Magento 2 source, I saw two places set the template helper/gallery.phtml.

  • vendor/magento/module-catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php
  • vendor/magento/module-product-video/Observer/ChangeTemplateObserver.php

a) If you want to set the template, you should use 2nd way.

b) In case using Observer, we can override the Observer(not recommend). Or, disable this Observer and use our custom Observer.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_product_gallery_prepare_layout">
        <observer name="change_template" disabled="true"/>
        <observer name="change_template_custom" instance="Vendor\Module\Observer\ChangeTemplateObserver" disabled="false"/>

Our ChangeTemplateObserver observer:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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