Reputation: 306
This code below is used to call the template from /app/code/ module.
$gridHtml = $block->getLayout()->createBlock(
'\Magento\Framework\View\Element\Template',
'custom_grid_new'
)->setTemplate('Magento_CustomGrid::product/view/templates/grid.phtml')
->toHtml();
How to set the template from following path
/app/design/frontend/Magento/luma/Custom_Grid/templates/grid1.phtml
tried this above in above code, but is not working.
Upvotes: 0
Views: 1326
Reputation: 306
$gridHtml = $block->getLayout()->createBlock(
'\Magento\Framework\View\Element\Template',
'custom_grid_new'
)->setTemplate('Magento_CustomGrid::grid.phtml')
->toHtml();
Upvotes: 0
Reputation: 633
That path you are using /app/design/frontend/Magento/luma/Custom_Grid/templates/grid1.phtml
makes it look as if you have just put your code insde the Magento Codebase.
You should never do that. Either extend luma-theme
with your-theme
and put your code there, or create your own module and extend the active theme via module.
With the "Theme option" you can call your templates directly.
With the "Module option" you can put your grid1.phtml
in YourVendor/YourModule/area/templates/grid1.phtml
while area
is either frontend
or adminhtml
and call it like this:
->setTemplate('YourVendor_YourModule::grid1.phtml')->toHtml();
Please refer to Magento 2 official documentation for theme inheritance.
Upvotes: 1