Magento2.1: How to override the template in custom module?












4














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?










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • 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: magentohtdocsappdesignadminhtmlAmastyHelloWorldProductVideotemplateshelpergallery.phtml Should this work?
    – Roninio
    Jan 15 '17 at 15:10












  • @Roninio you create a custom module or custom admin theme?
    – Khoa TruongDinh
    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 magentohtdocsappdesignadminhtmlAmastyHelloWorldMagento_ProductVideoviewadminhtmltemplateshel‌​pergallery.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
















4














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?










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • 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: magentohtdocsappdesignadminhtmlAmastyHelloWorldProductVideotemplateshelpergallery.phtml Should this work?
    – Roninio
    Jan 15 '17 at 15:10












  • @Roninio you create a custom module or custom admin theme?
    – Khoa TruongDinh
    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 magentohtdocsappdesignadminhtmlAmastyHelloWorldMagento_ProductVideoviewadminhtmltemplateshel‌​pergallery.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














4












4








4







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?










share|improve this question















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?







module magento-2.1 template overrides






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 15 '17 at 14:22









Khoa TruongDinh

21k63984




21k63984










asked Jan 15 '17 at 13:39









RoninioRoninio

1213




1213





bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • 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: magentohtdocsappdesignadminhtmlAmastyHelloWorldProductVideotemplateshelpergallery.phtml Should this work?
    – Roninio
    Jan 15 '17 at 15:10












  • @Roninio you create a custom module or custom admin theme?
    – Khoa TruongDinh
    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 magentohtdocsappdesignadminhtmlAmastyHelloWorldMagento_ProductVideoviewadminhtmltemplateshel‌​pergallery.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


















  • 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: magentohtdocsappdesignadminhtmlAmastyHelloWorldProductVideotemplateshelpergallery.phtml Should this work?
    – Roninio
    Jan 15 '17 at 15:10












  • @Roninio you create a custom module or custom admin theme?
    – Khoa TruongDinh
    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 magentohtdocsappdesignadminhtmlAmastyHelloWorldMagento_ProductVideoviewadminhtmltemplateshel‌​pergallery.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
















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




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: magentohtdocsappdesignadminhtmlAmastyHelloWorldProductVideotemplateshelpergallery.phtml Should this work?
– Roninio
Jan 15 '17 at 15:10






This is my path: magentohtdocsappdesignadminhtmlAmastyHelloWorldProductVideotemplateshelpergallery.phtml Should this work?
– Roninio
Jan 15 '17 at 15:10














@Roninio you create a custom module or custom admin theme?
– Khoa TruongDinh
Jan 15 '17 at 15:29




@Roninio you create a custom module or custom admin theme?
– Khoa TruongDinh
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




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 magentohtdocsappdesignadminhtmlAmastyHelloWorldMagento_ProductVideoviewadminhtmltemplateshel‌​pergallery.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




@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 magentohtdocsappdesignadminhtmlAmastyHelloWorldMagento_ProductVideoviewadminhtmltemplateshel‌​pergallery.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










1 Answer
1






active

oldest

votes


















0














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.



Vendor/Module/view/frontend/layout/checkout_cart_configure.xml



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




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="VendorModuleObserverChangeTemplateObserver" disabled="false"/>
</event>
</config>


Our ChangeTemplateObserver observer:



$observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f154783%2fmagento2-1-how-to-override-the-template-in-custom-module%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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.



    Vendor/Module/view/frontend/layout/checkout_cart_configure.xml



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




    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="VendorModuleObserverChangeTemplateObserver" disabled="false"/>
    </event>
    </config>


    Our ChangeTemplateObserver observer:



    $observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');





    share|improve this answer




























      0














      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.



      Vendor/Module/view/frontend/layout/checkout_cart_configure.xml



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




      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="VendorModuleObserverChangeTemplateObserver" disabled="false"/>
      </event>
      </config>


      Our ChangeTemplateObserver observer:



      $observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');





      share|improve this answer


























        0












        0








        0






        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.



        Vendor/Module/view/frontend/layout/checkout_cart_configure.xml



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




        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="VendorModuleObserverChangeTemplateObserver" disabled="false"/>
        </event>
        </config>


        Our ChangeTemplateObserver observer:



        $observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');





        share|improve this answer














        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.



        Vendor/Module/view/frontend/layout/checkout_cart_configure.xml



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




        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="VendorModuleObserverChangeTemplateObserver" disabled="false"/>
        </event>
        </config>


        Our ChangeTemplateObserver observer:



        $observer->getBlock()->setTemplate('Vendor_Module::helper/gallery.phtml');






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 15 '17 at 23:49

























        answered Jan 15 '17 at 14:58









        Khoa TruongDinhKhoa TruongDinh

        21k63984




        21k63984






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f154783%2fmagento2-1-how-to-override-the-template-in-custom-module%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            An IMO inspired problem

            Management

            Has there ever been an instance of an active nuclear power plant within or near a war zone?