0

I have checked the best solution. But not able to override the footer for my custom module.

Does anyone have a solution for this?

Thanks

  • You're using default Luma theme for you frontend ? Which section you want to override please attach that here with screenshot. – Kishan Savaliya Nov 5 at 9:43
  • Actually I need to add my custom jquery in footer. So that it will render on all CMS page – Shiwani Nov 5 at 9:43
  • You're using any custom theme ? – Kishan Savaliya Nov 5 at 9:46
  • No, I am not using custom theme. I need to override in my custom extension – Shiwani Nov 5 at 9:48
  • Okay you have any specific section which you want to override then can you please attach that in question with screenshot ? – Kishan Savaliya Nov 5 at 9:49
1

You need to create default.xml file in your custom module here

app/code/Vendor/Module/view/frontend/layout/default.xml

Content for this file is..

<?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>
        <referenceContainer name="footer">
            <block class="Magento\Framework\View\Element\Template" name="custom_jquery" after="-" template="Vendor_Module::custom_jquery.phtml"/>
        </referenceContainer>
    </body>
</page>

Now you need to create one template file here on this path in your custom module.

app/code/Vendor/Module/view/frontend/templates/custom_jquery.phtml

Content for this file is..

<script type="text/javascript">  
(function  () {    
    require(["jquery"], function($) {
        $(document).ready(function($) {
            /*You can add your custom jQuery code here*/
            alert("Hello");
        }); 
    });
})();
</script>

Hope this will help you!

0

Instead of override footer you can add your custom block into footer-container `default.xml``

<?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>
        <referenceContainer name="footer-container">
            <block class="Magento\Framework\View\Element\Template" name="custom_block-jquery" template="Vendor_ModuleName::html/customBlock.phtml"/>
        </referenceContainer>
    </body>
</page>

And add jquery content inside your phtml template or you can directly load jquery into default.xml file on header.

Anything you will place into default.xml will load on all pages.

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.