Learn two effective ways to call a phtml file in a Magento2 CMS page. You can either insert it directly in the page content or use a layout file for wider control.
Method 1 — Add PHTML via CMS Page Content
This method inserts a PHTML file directly into a specific CMS page.
Steps:
- Sign in to the Magento Admin dashboard.
- Go to Content → Pages and open the CMS page where you want your PHTML file to appear.
- In the Content editor, add this block code where you want the template to load

{{block class="Magento\Framework\View\Element\Template" template="Webkul_Test::test.phtml"}} - Save the page and flush the cache.
Magento will display the PHTML output inside your CMS page.

Method 2 — Use Layout XML to Call PHTML on All CMS Pages
Use this method when you want your PHTML file to show up across all CMS pages.
Steps:
- Create a layout file named: cms_page_view.xml inside your module’s layout folder:
app/code/Webkul/Test/view/frontend/layout/cms_page_view.xml
- Add this XML code:
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="custom.phtml.block" template="Webkul_Test::test.phtml"/> </referenceContainer> </body> </page> - Save the file and clear cache.
Now Magento automatically loads your PHTML template on all CMS pages.
Conclusion
Magento 2 provides flexible and reliable ways to include PHTML files in CMS pages, either by adding the template directly inside a specific page or by loading it globally through a layout XML file.
You can choose the method based on whether you need the template on a single page or across multiple CMS pages.
By following the correct file structure and using proper template references, you can ensure your custom content displays correctly.
Clearing the cache after implementation helps everything integrate smoothly with your Magento store.
Know more about Magento 2 CMS Page.
Looking to improve your store’s speed and overall performance? Check out our Magento 2 Speed & Optimization services.
For expert guidance or custom feature development, you may hire our Magento 2 developers to support your project.
Please explain also were the phtml file is located.
I have located it under app/code/Vendor/Modul/Block/Test.phtml and this does not work…
Thank for your help.
Kind regards