2

I've tried the same approach on Magento 2.1.7 and Magento 2.2.1 and it worked in M2.1.7 but not M2.2.1 unless something else is going on...

The approach I used was to edit default_head_blocks.xml in directory app/design/frontend/<VENDOR_NAME>/<MODULE_NAME>/Magento_Theme/layout which looks like:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 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>
        <script src="js/smartlook.js" />
        <!-- Also tried: <script src="Magento_Theme::js/smartlook.js" />  -->
    </head>
</page>

On Magento 2.1.7 I can see this file in the <head> section, but it doesn't seem to show up in Magento 2.2.1 after doing

setup:upgrade cache:flush setup:di:compile setup:static-content:deploy -f

Update

Either js/smartlook.js or Magento_Theme::js/smartlook.js my problem was a silly mistake :/

1
  • please assign module namespace in script tag Commented Nov 21, 2017 at 13:27

1 Answer 1

0

You need to add Namespace_Modulename before js declaration in script tag.

Now your js file will be at location,

app/code/{Namespace}/{Modulename}/view/frontend/web/js/smartlook.js

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <script src="Namespace_Modulename::js/jscolor.min.js"/>
    </head>
</page>

Replace {Namespace}/{Modulename} with your actuall module name path.

1
  • set <script src="Magento_Theme::js/jscolor.min.js"/> and run upgrade command Commented Nov 21, 2017 at 13:36

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.