1

How can I remove a phtml template file from my theme, but only from the home page?

My template file is "custome_home.phtml" at app/design/frontend/kalpak/ktheme/Magento_Theme/templates/html

2 Answers 2

0

First,you should find custome_home.phtml block name layout files or from backedn,

then using <referenceBlock name="BlockName" remove="true"/> from lyaout.

There are two way,you can do this:

From admin

Goto admin>Content>Page> then select your cms page>

and after that add below at code Design tab at your CMS home page at backend

<referenceContainer name="ParentContainerName">
     <referenceBlock name="BlocknameatLyaout" remove="true"/></referenceContainer>

From Layout file:

Goto app/design/frontend/[VendorTheme]/[ThemeName]/Magento_Cms/layout/cms_index_index.xml and below 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>
<!-- add this code for remove block -->
    <referenceBlock name="BlockName" remove="true"/>
    </body>
    </page>
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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