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
2
  • ` 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 Commented Sep 20, 2017 at 6:44
  • @AmitBera i already make sure there's no space before start Commented Sep 20, 2017 at 6:51

1 Answer 1

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.

4
  • 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 Commented Sep 20, 2017 at 7:57
  • Is this within the CMS page -> Design Tab -> Layout Update XML? Commented Sep 20, 2017 at 8:02
  • yes, fill it in that field for sure Commented Sep 20, 2017 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. Commented Sep 20, 2017 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.