Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

How to override template using helper function in Magento2

In this guide, we will learn how can we call our custom template file in layout referenceBlock from a helper function.

  1. Add the below code in your layout file:
<referenceBlock name="test_block">
            <action method="setTemplate">
                <argument name="template" xsi:type="helper" helper="Webkul\Test\Helper\Data::getTemplate"></argument>

            </action>
          
 </referenceBlock>

2. Create getTemplate function in your helper function.

public function getTemplate()
{
        
     $template =  'Webkul_Test::test.phtml';
        
     return $template;
}

We hope it will help you. Thank you!!

If any issue or doubt please feel free to mention in comment section.

We would be happy to help. Happy Coding!!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home