Magento 2 - How to call a custom phtml file in another phtml file, xml layout, static block and cms page

Custom file path
app/code/Magento/Theme/view/frontend/templates/html/test.phtml

calling in xml layout file
<block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"/>

calling in blocks and cms pages
{{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}}

calling in any phtml file
<?php include ($block->getTemplateFile('Magento_Theme::html/test.phtml')) ?>

or as before
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/test.phtml")->toHtml();?>

Comments