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.
- 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!!
Categories:
Uncategorized
View Comments
Comment or Ask a Question
Quick Links