In Magento 2, you should not use your module's templates in the theme file anymore (like back in Magento 1). Instead, your module directory should contain the code and the view files.
In your module directory, add the directory view/frontend/layout
. Then, add the correct layout file for the scope. You won't use customhome.xml
. I assume you want to add something to the homepage, so simply create a file with the name cms_index_index.xml
.
Then add the following code:
<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="Myname\Mymodule\Block\Myblockname" name="customhome" template="Myname_Mymodule::customhome.phtml" />
</referenceContainer>
</body>
</page>
The filename (cms_index_index.xml
) determines where your content is shown (you don't use different layout handles inside the same XML file anymore). So, if you want to show it on every page, the file should be named default.xml
; if you want to show it on product pages, the file should be named catalog_product_view.xml
, etc.
customehome.xml
belongs. Is this a controller or something else?