0

I have created New page_layout empty.xml. I need to remove some JS and CSS from this layout. I already try <remove src="print.css"/> But it gives an error Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'remove', attribute 'src': The attribute 'src' is not allowed.

app/design/frontend/Sm/market/Magento_Theme/page_layout/empty.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="head" remove="true"/>
    <referenceContainer name="header" remove="true"/>
    <referenceContainer name="menu" remove="true"/>
    <referenceContainer name="notifications" remove="true"/>
    <referenceContainer name="footer" remove="true"/>
    <referenceContainer name="body" remove="true"/>
    <remove src="print.css"/>
</layout>
0

Here is the best example to remove js or css using layout xml files.

   <head>
    <!-- Remove local styles resources -->
    <remove src="css/styles-m.css" />
    <remove src="<Namespace>_<ModuleName>::css/styles.css" />

    <!-- Remove js resources -->
    <remove src="my-js.js" />
    <remove src="Magento_Catalog::js/sample1.js" />

    <!-- Remove external resources -->
    <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" />
    <remove src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" />
    <remove src="http://fonts.googleapis.com/css?family=Montserrat" />
   </head>

For more information, you can see here, Remove static links using layout

Please check like this and if this help you then hit like.

Thank you,

Hiren Patel

1
  • Your code will work for the layout file But I need the solution for the page_layout file. Oct 5 '20 at 5:39

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.