0

I've created a custom module that holds a simple phtml file, block class to include elements into the phtml file and a default.xml within my Module/view/frontend/layout.

However I am struggling to add my phtml to my page using the default.xml within my module, however I can add this using the default.xml within my theme.

Heres the contents of my xml within my module:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<body>
    <referenceBlock name="autosmart.logo" remove="true"/>
    <referenceContainer name="header.container">
        <block class="Autosmart\DistributorSearch\Block\DistributorSearch" name="distributor.search" template="distributor-search.phtml"></block>
    </referenceContainer>
</body>
</page>

Do I need to do anything to use this module default.xml rather than having to add my phtml to the page using my theme default.xml?

1 Answer 1

1

The template should be Autosmart_DistributorSearch::path/to/distributor-search.phtml

Please note that the template parameter starts from Autosmart/DistributorSearch/view/frontend/templates

4
  • My phtml file is within Autosmart/DistributorSearch/view/frontend/templates and the coding is exactly the same within my theme default xml which is working?
    – lky
    Commented Jun 23, 2017 at 10:45
  • Yes, you should put the template file under Autosmart/DistributorSearch/view/frontend/templates. Of course, you can create and directories as you want, just pointing to the right file is OK. If still doesn't work, check if the module is enabled and clear cache.
    – PY Yick
    Commented Jun 23, 2017 at 11:28
  • Module is enabled and I have cleared cache, the issue I am having is that I cannot add this to the page from the xml in my module, but I can in my theme default.xml using the same coding? Do I need to do anything to tell magento to run my xml in my module?
    – lky
    Commented Jun 23, 2017 at 12:06
  • have you fixed this @heady12 i am facing the same issue Commented Jan 6, 2020 at 14:23

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.