Piyush Jain
Piyush Jain

Reputation: 1986

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

My file is in app/design/frontent/vendor_name/theme/Magento_Theme/templates/html/test.phtml

How to call this files in another phtml file, xml layout, static block and cms page

Please Help

Upvotes: 3

Views: 15258

Answers (1)

RichTea
RichTea

Reputation: 1435

In xml layout file

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

In cms blocks and cms pages

{{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}}

In a phtml file

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

Upvotes: 14

Related Questions