This code below is used to call the template from /app/code/ module.
$gridHtml = $block->getLayout()->createBlock(
'MagentoFrameworkViewElementTemplate',
'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.
2
Answers
Reference: https://community.magento.com/t5/Magento-2-x-Programming/Magento-2-Call-phtml-path-from-frontend-folder/m-p/463320/thread-id/12091#M12094
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
withyour-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
inYourVendor/YourModule/area/templates/grid1.phtml
whilearea
is eitherfrontend
oradminhtml
and call it like this:Please refer to Magento 2 official documentation for theme inheritance.