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.
That path you are using
/app/design/frontend/Magento/luma/Custom_Grid/templates/grid1.phtmlmakes it look as if you have just put your code insde the Magento Codebase.You should never do that. Either extend
luma-themewithyour-themeand 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.phtmlinYourVendor/YourModule/area/templates/grid1.phtmlwhileareais eitherfrontendoradminhtmland call it like this:Please refer to Magento 2 official documentation for theme inheritance.