1

I want to add css from module to my custom cms page like this:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="Test_Customlayout::css/test.css" /> 
    </head>
    <body>
        <referenceContainer name="header.container">
          <block class="Magento\Cms\Block\Block" name="test" before="header">
              <arguments>
                  <argument name="block_id" xsi:type="string">23</argument>
              </arguments>
          </block>
        </referenceContainer>
        <referenceContainer name="page.top">
           <referenceBlock name="breadcrumbs" remove="true"/>
        </referenceContainer>
    </body>
</page>

but I've got an error like this while I'm trying to save the page:

Please correct the XML data and try again. XML declaration allowed only at the start of the document Line: 1
  • ` start of the document Line: 1` means there have some space before start <?xml ,Please write <?xml version="1.0"?> before start amlny code in x – Amit Bera Sep 20 '17 at 6:44
  • @AmitBera i already make sure there's no space before start – Idham Choudry Sep 20 '17 at 6:51
0

Within layout update XML for CMS page there is no need for a lot of this code. Try below?

    <head>
      <css src="Test_Customlayout::css/test.css" /> 
    </head>
    <referenceContainer name="header.container">
      <block class="Magento\Cms\Block\Block" name="test" before="header">
          <arguments>
              <argument name="block_id" xsi:type="string">23</argument>
          </arguments>
      </block>
    </referenceContainer>
    <referenceContainer name="page.top">
       <referenceBlock name="breadcrumbs" remove="true"/>
    </referenceContainer>

This saved fine in my 2.1.7 version of Magento.

  • i'm using 2.1.8 and i got the following error : Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1 – Idham Choudry Sep 20 '17 at 7:57
  • Is this within the CMS page -> Design Tab -> Layout Update XML? – harri Sep 20 '17 at 8:02
  • yes, fill it in that field for sure – Idham Choudry Sep 20 '17 at 8:06
  • That is strange i remember this error happening to me a while back not sure why it works fine for me now however. – harri Sep 20 '17 at 8:18

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.