2

I created a few ."phtml" files in my custom theme. Currently, I create a block & widget in the backend to call them on my cms home page.
Is that the correct way?
If I, for example, want to use my custom theme on another magento2 installation, these ".phtml" files aren't included on the cms home page anymore and blocks & widgets need to be created manually.

Should I handle that stuff different? Maybe include into XML? If yes, how?

Thanks a lot for clarification :))

4

app/design/frontend/Vendor/theme/Magento_Cms/layout/cms_index_index.xml

<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" template="Magento_Theme::yourphtmlfile.phtml" name="myphtml" />
        </referenceContainer>
    </body>
</page>

or direclty in CMS home page content as follows

{{block class="Magento\Framework\View\Element\Template" template="Magento_Theme::yourphtmlfile.phtml"}}
| improve this answer | |
0

Use this code in your cms content:

{{block class="Magento\Framework\View\Element\Template" template="Namespace_Module::test.phtml"}}

where Namespace_Module will be your module name in which the phtml exists such as Magento_Catalog.

| improve this answer | |
-1

Copy app/design/frontend/Vendor/theme/Magento_Cms/layout/cms_index_index.xml to your theme directory app/design/frontend/namespace/themename/Magento_Theme/layout/cms_index_index.xml

and add following in it:-

<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" template="Magento_Theme::home_page_ptml.phtml" name="home_page_ptml" />
        </referenceContainer>
    </body>
</page>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.