0

I am new to magento 2 and i am integrating some payment gateway in JS.

I need to add script.js in default.html which is at this path location.

magento2\app\code\vendor\module_name\view\frontend\web\template\payment\default.html

Location of JS script file is at this path.

magento2\app\code\vendor\module_name\js\script.js

2

add your Js file

app/code/vendor/module/view/frontend/web/js/script.js

script.js:

Then add Js File to Your layout File.

app/code/vendor/module/view/frontend/layout/test_index_index.xml

like this:

 <?xml version="1.0"?>
     <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
       <head>
          <css src="css/mycss.css" />
          <script src="js/script.js"/>
     </head> 
       <body>
         <referenceContainer name="content">
              <block class="vendor\Module\Block\class" template="vendor_Module::class.phtml"/>
         </referenceContainer>  
     </body> 
    </page>
0

Adding the head code to checkout_index_index.xml solved my problem

app\code\vendor_name\module_name\view\frontend\layout\checkout_index_index.xml

<head>
    <!-- Add local resources -->
    <script src="vendor_module::lib/dist/libscript.min.js"/>
</head>

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.