Skip to main content
deleted 1 character in body
Source Link
CompactCode
  • 2.5k
  • 1
  • 23
  • 36

To be complete this is how to overwrite a home page phtml fille from a theme :

App/Design/Vendor/Theme/Magento_Theme/layouts.xml

<?xml version="1.0" encoding="UTF-8"?>
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">

    <layout id="custom_home">
        <label translate="true">custom_home</label>
    </layout>
</page_layouts>

This file is responsible for creating a custom page layout. You can set your page layouts in your Magento Admin section under Content->Page->select page-> Design

App/Design/Vendor/Theme/Magento_Theme/page_layout/custom_home.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
    </referenceContainer>
</layout>

In this file you can decide your markup of the page. You can add or delete blocks or move container/blocks according to the default standards. For example i needed to overwrite the catalog.topnav menu to create a Mega Menu and in my module that creates it i used (this can also be done in the theme) :

<referenceBlock name="catalog.topnav" template="Designit_MegaMenu2::html/topmenu.phtml" class="Designit\MegaMenu2\Block\Html\MegaMenu">
</referenceBlock>

More info about that : Custom Layout

Within this XML you can change template fillesfiles from existing magento blocks or add blocks however you want.

Note : This is only true if you have Magento_Blank or something as a parent which i highly recommend!

Note 2 : A home page is not just 1 phtml file. It consists out of different blocks and i really recommend adjusting these blocks. This is the only correct way of theming your website

To be complete this is how to overwrite a home page phtml fille from a theme :

App/Design/Vendor/Theme/Magento_Theme/layouts.xml

<?xml version="1.0" encoding="UTF-8"?>
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">

    <layout id="custom_home">
        <label translate="true">custom_home</label>
    </layout>
</page_layouts>

This file is responsible for creating a custom page layout. You can set your page layouts in your Magento Admin section under Content->Page->select page-> Design

App/Design/Vendor/Theme/Magento_Theme/page_layout/custom_home.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
    </referenceContainer>
</layout>

In this file you can decide your markup of the page. You can add or delete blocks or move container/blocks according to the default standards. For example i needed to overwrite the catalog.topnav menu to create a Mega Menu and in my module that creates it i used (this can also be done in the theme) :

<referenceBlock name="catalog.topnav" template="Designit_MegaMenu2::html/topmenu.phtml" class="Designit\MegaMenu2\Block\Html\MegaMenu">
</referenceBlock>

More info about that : Custom Layout

Within this XML you can change template filles from existing magento blocks or add blocks however you want.

Note : This is only true if you have Magento_Blank or something as a parent which i highly recommend!

Note 2 : A home page is not just 1 phtml file. It consists out of different blocks and i really recommend adjusting these blocks. This is the only correct way of theming your website

To be complete this is how to overwrite a home page phtml fille from a theme :

App/Design/Vendor/Theme/Magento_Theme/layouts.xml

<?xml version="1.0" encoding="UTF-8"?>
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">

    <layout id="custom_home">
        <label translate="true">custom_home</label>
    </layout>
</page_layouts>

This file is responsible for creating a custom page layout. You can set your page layouts in your Magento Admin section under Content->Page->select page-> Design

App/Design/Vendor/Theme/Magento_Theme/page_layout/custom_home.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
    </referenceContainer>
</layout>

In this file you can decide your markup of the page. You can add or delete blocks or move container/blocks according to the default standards. For example i needed to overwrite the catalog.topnav menu to create a Mega Menu and in my module that creates it i used (this can also be done in the theme) :

<referenceBlock name="catalog.topnav" template="Designit_MegaMenu2::html/topmenu.phtml" class="Designit\MegaMenu2\Block\Html\MegaMenu">
</referenceBlock>

More info about that : Custom Layout

Within this XML you can change template files from existing magento blocks or add blocks however you want.

Note : This is only true if you have Magento_Blank or something as a parent which i highly recommend!

Note 2 : A home page is not just 1 phtml file. It consists out of different blocks and i really recommend adjusting these blocks. This is the only correct way of theming your website

Source Link
CompactCode
  • 2.5k
  • 1
  • 23
  • 36

To be complete this is how to overwrite a home page phtml fille from a theme :

App/Design/Vendor/Theme/Magento_Theme/layouts.xml

<?xml version="1.0" encoding="UTF-8"?>
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">

    <layout id="custom_home">
        <label translate="true">custom_home</label>
    </layout>
</page_layouts>

This file is responsible for creating a custom page layout. You can set your page layouts in your Magento Admin section under Content->Page->select page-> Design

App/Design/Vendor/Theme/Magento_Theme/page_layout/custom_home.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
    </referenceContainer>
</layout>

In this file you can decide your markup of the page. You can add or delete blocks or move container/blocks according to the default standards. For example i needed to overwrite the catalog.topnav menu to create a Mega Menu and in my module that creates it i used (this can also be done in the theme) :

<referenceBlock name="catalog.topnav" template="Designit_MegaMenu2::html/topmenu.phtml" class="Designit\MegaMenu2\Block\Html\MegaMenu">
</referenceBlock>

More info about that : Custom Layout

Within this XML you can change template filles from existing magento blocks or add blocks however you want.

Note : This is only true if you have Magento_Blank or something as a parent which i highly recommend!

Note 2 : A home page is not just 1 phtml file. It consists out of different blocks and i really recommend adjusting these blocks. This is the only correct way of theming your website