0

I am facing the error in Magento Localhost which is

Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid XML in file /var/www/html/magento/app/code/Mb/Customizations/etc/frontend/events.xml: Element 'event', attribute 'cachable': The attribute 'cachable' is not allowed. Line: 9

In the image you can see the error enter image description here

So after That I tried to remove cacheable from the core class magento/app/code/Mb/Customizations/etc/frontend/events.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

    <event name="layout_generate_blocks_after">
        <observer name="cust_productCanonical" instance="Mb\Customizations\Observer\ProductCanonical"/>
    </event>

    <event name="controller_action_predispatch_checkout_index_index" cachable="false">
        <observer name="checkcout_page_pre" instance="Mb\Customizations\Observer\Preloadtab" />
    </event>
    <event name="controller_action_postdispatch_checkout_index_index" cachable="false">
        <observer name="checkcout_page_post" instance="Mb\Customizations\Observer\Loadtab" />
    </event>

</config>

but after removing the casheable from the above xml file it gives me some else error

1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid XML in file /var/www/html/magento/app/code/TM/Crm/etc/frontend/events.xml: Element 'config': Missing child element(s). Expected is ( event ). Line: 2

enter image description here

magento/app/code/TM/Crm/etc/frontend/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

<!--     <event name="checkout_onepage_controller_success_action">
        <observer name="tm_crm_checkout_onepage_controller_success_action" instance="TM\Crm\Observer\Crm" />
    </event> -->

</config>

So how can I remove this error and what is the problem in the above xml file. Thanks

  • cachable="false" should only be used for blocks not for events. here is the full docs from magento devdocs.magento.com/guides/v2.2/extension-dev-guide/cache/… – Aman Alam May 31 at 6:00
  • ok fine but when I remove the cachable then it give me another error 1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid XML in file /var/www/html/magento/app/code/TM/Crm/etc/frontend/events.xml: Element 'config': Missing child element(s). Expected is ( event ). Line: 2 – Asad Khan May 31 at 6:02
  • Cachable? Cashable? Cacheable? Man, that typo variations can kill you :) My bet is you may have some white space in that XML between config and event after cleaning the wrong references – Raul Sanchez May 31 at 6:02
  • Please post your XML? magento/app/code/TM/Crm/etc/frontend/events.xml – Khoa TruongDinh May 31 at 6:05
  • @KhoaTruongDinh Sir question updated kindly check it – Asad Khan May 31 at 6:11
1

Just make the xml look like this:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_generate_blocks_after">
        <observer name="cust_productCanonical" instance="Mb\Customizations\Observer\ProductCanonical"/>
    </event>
    <event name="controller_action_predispatch_checkout_index_index">
        <observer name="checkcout_page_pre" instance="Mb\Customizations\Observer\Preloadtab" />
    </event>
    <event name="controller_action_postdispatch_checkout_index_index">
        <observer name="checkcout_page_post" instance="Mb\Customizations\Observer\Loadtab" />
    </event>
</config>

If you don't have any event tags in your file, remove the file completely. You cannot have an empty file.

  • Sir I tried this but it gives me an error Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid XML in file /var/www/html/magento/app/code/TM/Crm/etc/frontend/events.xml: Element 'config': Missing child element(s). Expected is ( event ) – Asad Khan May 31 at 6:18
  • Please clear cache after changes suggested by Marius . – padhiyar gaurang May 31 at 6:24
0
<?xml version="1.0" encoding="UTF-8"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="layout_generate_blocks_after">
            <observer name="cust_productCanonical" instance="Mb\Customizations\Observer\ProductCanonical"/>
        </event>
    </config>

Make sure your XML is UTF-8 formatted, Then do cache flush and try it.

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.