0

I have used the below code to call example js file which is located in Magento_Theme folder of the theme.

<referenceContainer name="before.body.end">
    <block class="Magento\Framework\View\Element\Text" name="exampleScript">
        <arguments>
            <argument name="text" xsi:type="string"><![CDATA[<script type="text/javascript" src="Magento_Theme::js/example.js"></script>]]></argument>
        </arguments>
    </block>
</referenceContainer>

But this gives 404-Error as it goes to find from URL from where

/pub/static/version1564550212/frontend/Themevendor/Themename/nl_NL/Magento_Theme/js

path is missing.

2
  • check my answer Jul 31, 2019 at 11:07
  • Yes Js is now loaded, but my main purpose was to load after all js is merged, Using this code it gives me error $ is not defined. any idea about that?
    – Mona Mehta
    Jul 31, 2019 at 11:13

1 Answer 1

1

Try Following way....

<referenceContainer name="before.body.end">
    <block class="Magento\Framework\View\Element\Text" name="exampleScript">
        <arguments>
            <argument name="text" xsi:type="string"><![CDATA[<script type="text/javascript" src="js/example.js"></script>]]></argument>
        </arguments>
    </block>
</referenceContainer>

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.