8

I am trying to override default_head_blocks.xml like below

vendor\magento\module-theme\view\frontend\layout\default_head_blocks.xml

<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <css src="mage/calendar.css"/>
        <script src="requirejs/require.js"/>
    </head>
    <body>
        <referenceContainer name="after.body.start">
            <block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Theme::js/components.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>

app\design\frontend\Enterprise\Orange\Magento_Theme\layout\default_head_blocks.xml

<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
                <head>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
                                <link src="js/customercookie.js"/>
                                <link src="js/customercookie.js"/>
                                <link src="Orange_Webform::js/mnpform.js"/>
        <css src="mage/calendar.css"/>
        <css src="common-header/css/custom.css"/>
                                <script src="shm/shm.js"/>
                                <script src="common-header/js/custom.js"/>
        <script src="requirejs/require.js"/>
    </head>
    <body>
        <referenceContainer name="after.body.start">
            <block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Theme::js/components.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>

Just I want to load shm/shm.js before requirejs/require.js

Please do the needfull

2
  • You need to make sure that your module loads before magento's so that your javscript is added first. E.g name your package AaEnterprise_Orange, with what you have it should work. Commented Jun 22, 2018 at 18:29
  • Can anyone answer this question?I have same concern.... Commented Aug 28, 2018 at 11:22

1 Answer 1

-2

To load custom js before require.js than add custom js in below XML path

app\design\frontend\Enterprise\Orange\Magento_Theme\layout\override\base\default_head_blocks.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <head>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
                            <link src="js/customercookie.js"/>
                            <link src="js/customercookie.js"/>
                            <link src="Orange_Webform::js/mnpform.js"/>
    <css src="mage/calendar.css"/>
    <css src="common-header/css/custom.css"/>
                            <script src="shm/shm.js"/>
                            <script src="common-header/js/custom.js"/>
    <script src="requirejs/require.js"/>
  </head>
  <body>
    <referenceContainer name="after.body.start">
        <block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Theme::js/components.phtml" before="-"/>
    </referenceContainer>
  </body>
</page>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.